繁体   English   中英

ZedGraph实时数据绘图C#

[英]ZedGraph RealTime Data Plotting C#

        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是传入串行端口数据的长度。 此代码在计时器(20ms)中正常工作,并在每个刻度处绘制数据。 但是,如果我将此方法移动到类中,它将无法正常工作。 它绘制了过快和错误的数据。

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秒的记录。 我的方法没有这样的数据。

我假设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();
}

至于快速绘制,它只会像你告诉它一样快。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM