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