关于一个在ZedGraph中删掉多个曲线的问题

jingtianziduan 2018-11-20 06:46:03
需求:利用zedgraph绘制多条曲线,动态随移动物体显示,现在需要保证第一个物体移动过的地方,单条曲线仅显示500个点,每个移动物体对应显示5条不同曲线;当有两个类似的物体运动时,需分别画对应的5条曲线(横坐标不同)。
问题:目前只有一个运动物体时,通过周期性myPane.CurveList.Clear();清除当前5条各500个点的数组,然后重画数据更新后的这5个数组。没有曲线显示了。但如果去掉myPane.CurveList.Clear();这句的时候,zedgraph会显示重叠的多条曲线。证明数据正确,但改回去之后就没有曲线,请大神指导,谢谢!
...全文
66 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
jingtianziduan 2018-11-30
  • 打赏
  • 举报
回复
看了下面的介绍,来了感觉,问题已解决。其实很简单,只是自己接触这个控件时间太短,没有灵活变通。
The ZedGraphControl can display dynamic or static data. For dynamic displays, each time you want to add data to a graph, you will need to do the following:


1.Find the CurveItem of interest within the GraphPane.CurveList collection
2.Access the PointPairList (or other IPointListEdit type) for the CurveItem, and add the new data or modify the existing data as required
3.Call ZedGraphControl.AxisChange() to update the auto-scaled axis ranges
4.Call Form.Invalidate() to update the graph

The data points are stored with each CurveItem as a reference to an IPointList interface in CurveItem.Points. Note that this point list reference can be any class that implements IPointList. If it also implements IPointListEdit, thenIPointListEdit.Add() and IPointListEdit.RemoveAt() methods will be available.

The code sample is for a form that implements a ZedGraphControl with a Timer event to show dynamically updated data. You can download the complete project from the links below:
jingtianziduan 2018-11-20
  • 打赏
  • 举报
回复
这部分代码如下:
public void MainAddCurveData(int index, double[] Xdatas, double[] Ydatas)
{
for (int i = 0; i < Xdatas.Length; i++)
{
MainPointPairLists[index].Add(Xdatas[i], Ydatas[i]);
}

zedGraphControlUp.AxisChange();
zedGraphControlUp.Refresh();
}

public void MainAddCurveData(double[] speed, double[] v_max, double[] v_min, double[] acc, double[] dis)
{
zedGraphControlUp.GraphPane.CurveList.Clear();
MainAddCurveData(0, dis, speed);
MainAddCurveData(1, dis, v_max);
MainAddCurveData(2, dis, v_min);
MainAddCurveData(3, dis, acc);

}

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧