如何使用C#双Y轴ZedGraph图形添加实时数据? [英] How to add real-time data in a dual-Y-axis ZedGraph graph using C#?
问题描述
有关我的项目,我需要实时数据添加和更新到我的双y轴图。在Y和Y2值共享相同的X值,我创造了它了。现在我有一个功能,增加了新的点对到曲线列表
For my project, I need to add and update real-time data to my dual y-axis graph. The Y and Y2 values share the same X value, and I created it already. Now I have a function that adds the new point pairs to the curve lists.
下面是我的问题:我的Y和Y2值总是添加到的曲线列表第一条曲线。 ?我怎样才能加入到第二条曲线列表,我图的Y2值
Here is my problem: My Y and Y2 values are always added to the curve list of the first curve. How can I get the Y2 value added to the second curve list in my graph?
下面是我的函数代码:
private void AddDataToGraph(ZedGraphControl zg1, XDate xValue, double yValue1, double yValue2)
{
// Make sure that the curvelist has at least one curve.
if (zg1.GraphPane.CurveList.Count <= 0)
return;
// Get the first CurveItem in the graph.
LineItem curve = zg1.GraphPane.CurveList[0] as LineItem;
if (curve == null)
return;
// Get the PointPairList.
IPointListEdit list = curve.Points as IPointListEdit;
IPointListEdit list2 = 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 || list2 == null)
return;
// Add new data points to the graph.
list.Add(xValue, yValue1);
list2.Add(xValue, yValue2);
// Force redraw.
zg1.Invalidate();
}
他如何能Y2值被添加到第二曲线列表?
How can he Y2 values be added to the 2nd curve list?
推荐答案
发现了一个可能的解决方案我自己。这里是我的代码更改:
Found a possible solution myself. Here are my code changes:
private void AddDataToGraph(ZedGraphControl zg1, XDate xValue, double yValue1, double yValue2)
{
// Make sure that the curvelist has at least one curve
if (zg1.GraphPane.CurveList.Count <= 0)
return;
// Get the first CurveItem in the graph
LineItem curve = zg1.GraphPane.CurveList[0] as LineItem;
LineItem curve2 = zg1.GraphPane.CurveList[1] as LineItem;
if (curve == null || curve2 == null)
return;
// Get the PointPairList
IPointListEdit list = curve.Points as IPointListEdit;
IPointListEdit list2 = curve2.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 || list2 == null)
return;
// add new data points to the graph
list.Add(xValue, yValue1);
list2.Add(xValue, yValue2);
// force redraw
zg1.Invalidate();
}
重要的是使用索引中的CurveList [I] 。所以,[0]是我与Y值和[1]是我与Y2值曲线等曲线。
The important thing is to use the index in the "CurveList[i]". So [0] is my curve with the Y values and [1] is my curve with the Y2 values, and so on.
我希望这有助于任何人谁拥有相同或类似的问题。
I hope this helps anybody who has the same or similar problem.
这篇关于如何使用C#双Y轴ZedGraph图形添加实时数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!