2

我搜索了一些 ZedGraph 的例子,但我无法执行我想要的。我每 20 毫秒绘制一次实时数据,我想在 x 轴上显示系统时间(使用 ZedGraph 类XAxis)。但是,当我尝试在 x 轴上绘制毫秒时,我看不到任何数据。这是我的代码:

//X-Axis Settings
pane.XAxis.Scale.MinorStep = 1;
pane.XAxis.Scale.MajorStep = 5;
pane.XAxis.Type = AxisType.Date;
pane.XAxis.Scale.Format = "HH:mm:ss.fff";
pane.XAxis.Scale.Min = new XDate(DateTime.Now);
pane.XAxis.Scale.Max = new XDate(DateTime.Now.AddSeconds(10));
pane.XAxis.Scale.MinorUnit = DateUnit.Second;
pane.XAxis.Scale.MajorUnit = DateUnit.Second;

XDate time = new XDate(DateTime.Now.ToOADate());
for (int i = 1; i < 16; i++)
{
    listAuido.Add(time, (double)Read_Data1[i]);
}

Scale xScale1 = zgcMasterPane.MasterPane.PaneList[0].XAxis.Scale;
if (time.XLDate > xScale1.Max)
{
   xScale1.Max = (XDate)(DateTime.Now.AddSeconds(1));
   xScale1.Min = (XDate)(DateTime.Now.AddSeconds(-20));
}

编辑:这个代码结构解决了我的问题。

4

1 回答 1

3

以下代码将所有数据绘制在同一个 x 点上!

for (int i = 1; i < 16; i++)
{
    listAuido.Add((XDate)(DateTime.Now.Millisecond), (double)Read_Data1[i]);
}

如果您不希望 XAxis 看起来那样,为什么要将它设置为日期格式?

好的,试试这个:

//Declare the x coordinate (time) variable
double xValue = 0;

//Setting the axis
pane.XAxis.Scale.MinorStep = 1;
pane.XAxis.Scale.MajorStep = 5;
pane.XAxis.Scale.Max = 0;
pane.XAxis.Scale.Min = -10;

//drawing the data
private void draw(double dataValue)
{
    LineItem curve1 = zedGraphControl1.GraphPane.CurveList[0] as LineItem;
    IPointListEdit list1 = curve1.Points as IPointListEdit;

    list1.Add(xValue*(20/1000), dataValue); //

    //Scroll
    Scale XScale = zedGraphControl1.GraphPane.XAxis.Scale as Scale;
    XScale.Max = xValue*(20/1000);
    XScale.Min = XScale.Max - 10;

    xValue++;
    zedGraphControl1.AxisChange();
    zedGraphControl1.Invalidate();
}

//Now you call the function draw every 20 ms using a [Timer][1] for example
private void timer1_Tick(object sender, EventArgs e)
{
    draw(data[xValue]);
}

顺便说一句,我在这里没有使用 MasterPane。

于 2013-12-12T04:33:12.327 回答