ZedGraph横轴显示时间

初始化zedgraph控件

            myPane = zedGraphControl1.GraphPane;
            myPane.XAxis.Scale.IsVisible = true;
            myPane.XAxis.Scale.MajorStepAuto = true;
            myPane.XAxis.Scale.MinorStepAuto = true;
            myPane.XAxis.Type = AxisType.Date;
            myPane.XAxis.Scale.Format = "yyyy-MM-dd hh:mm:ss";
            myPane.XAxis.Scale.Format = "yyyy-MM-dd hh:mm:ss";
            myPane.XAxis.Title.Text = "时间数据";
            myPane.YAxis.Title.Text = "压力数据(mbr)";
            myPane.Title.Text = "压力传感器数据";

数据显示

            zgc.GraphPane.CurveList.Clear();//清除第一次画的点集
            zgc.Refresh();
            myPane.XAxis.Scale.IsVisible = true;
            myPane.XAxis.Scale.MajorStepAuto = true;
            myPane.XAxis.Scale.MinorStepAuto = true;
            myPane.XAxis.Type = AxisType.Date;

 

 

             //获取点集数据

             xData = (double)new XDate(Convert.ToDateTime(dt.Rows[i][0]));//获得x轴时间的点
                dtime1 = Convert.ToDateTime(dt.Rows[i][0]);
                ts = Convert.ToDateTime(dt.Rows[i + 1][0]) -dtime1 ;
                ss = ts.TotalSeconds / 10;
                for (int j = 0; j < 10; j++)
                {
                    dtime2=dtime1.AddSeconds(j * ss);
                    xData = (double)new XDate(dtime2);
                    YPress = Convert.ToDouble (Convert.ToDouble (dt.Rows[i][1 + j]).ToString ("##.#")); //确认小数的文书                    PressList.Add(xData, YPress);
                }

             //加载点集到画布上,设置显示

              myPane.XAxis.Scale.IsVisible = true;
           // myPane.XAxis.Scale.MajorStepAuto = true;
           // myPane.XAxis.Scale.MinorStepAuto = true;
            myPane.XAxis.Scale.Format = "yyyy-MM-dd hh:mm:ss";//横轴格式
            myPane.XAxis.Scale.MajorUnit = DateUnit.Millisecond ;
            myPane.XAxis.Type = AxisType.Date;
            myPane.XAxis.MajorGrid.IsVisible = true;
            myPane.XAxis.MajorGrid.Color = Color.Green;
            myPane.XAxis.MinorGrid.IsVisible = true;
            myPane.XAxis.MinorGrid.Color = Color.Green;

你可能感兴趣的:(C#,学习)