3
        public void DrawingPulseData(byte[] data)
        {

            // Make sure that the curvelist has at least one curve
            if (PulseControl.GraphPane.CurveList.Count <= 0)
                return;

            // Get the first CurveItem in the graph
            LineItem curve = PulseControl.GraphPane.CurveList[0] as LineItem;
            if (curve == null)
                return;

            // Get the PointPairList
            IPointListEdit list = curve.Points as IPointListEdit;
            // If this is null, it means the reference at curve.Points does not
            // support IPointListEdit, so we won't be able to modify it
            if (list == null)
                return;

            double time = (Environment.TickCount - tickStart) / 1000.0;

            for (int i = 0; i < count; i++)
            {
                list.Add(time, (double)data[i]);
            }

            Scale xScale = PulseControl.GraphPane.XAxis.Scale;

            if (time > xScale.Max - xScale.MajorStep)
            {
                xScale.Max = time + xScale.MajorStep;
                xScale.Min = xScale.Max - 30.0;
            }

            // Make sure the Y axis is rescaled to accommodate actual data
            PulseControl.AxisChange();
            // Force a redraw
            PulseControl.Invalidate();

            count = 0;
        }

你好。我正在使用这种方法在 zedgraph 中绘制实时数据。count是传入串行端口数据的长度。此代码在计时器(20 毫秒)中运行良好,并在每个滴答时绘制数据。但是,如果我将此方法移动到一个类中,它将无法正常工作。它绘制太快和错误的数据。

public static void DrawingPulseData(byte[] data,ZedGraphControl zgc,int count, int TickStart)

在将其移入课堂后,我更改了这样的参数。我将 PulseControl 更改为 zgc,将 tickstart 更改为 TickStart。我不明白为什么它与第一个代码不同。

在此处输入图像描述

在第一张图片中,使用@discomurray 提供的代码,我在 if 的范围之外编写了这个代码语句。它给了我这样的数据。

   Scale xScale = zgc.GraphPane.XAxis.Scale;
   xScale.Max = now;
   xScale.Min = now - 30.0;

在此处输入图像描述

如果我将相同的代码语句写入 if 的范围数据,则如上图所示。这是一个10秒的记录。我的方法没有这样的数据。

4

1 回答 1

2

我假设 tickCount 是数据缓冲区的开始时间。

将数据添加到列表时,您需要更改列表中每个点的 x 值(时间)。

public static void DrawPulseData(byte[] data, ZedGraphControl zgc, int count, int tickStart)
{
    double now = Environment.TickCount / 1000.0;

    if (count != 0)
    {
        double span = (now - tickStart);

        double inverseRate = span / count;

        for (int i = 0; i < count; i++)
        {
            list.add(tickStart + ((i+1) * inverseRate), data[i]);
        }
    }

    Scale xScale = zgc.GraphPane.XAxis.Scale;
    xScale.Max = now;
    xScale.Min = now - 30.0;

    PulseControl.AxisChange();
    PulseControl.Invalidate();
}

至于快速绘图,它只会按照您告诉它的速度进行。

于 2013-09-11T23:06:30.540 回答