gpt4 book ai didi

c# - 如何使用 C# 在双 Y 轴 ZedGraph 图中添加实时数据?

转载 作者:行者123 更新时间:2023-11-30 13:42:17 24 4
gpt4 key购买 nike

对于我的项目,我需要向我的双 y 轴图表添加和更新实时数据。 Y 和 Y2 值共享相同的 X 值,我已经创建了它。现在我有一个函数可以将新的点对添加到曲线列表中。

这是我的问题:我的 Y 和 Y2 值总是添加到第一条曲线的曲线列表中。如何将 Y2 值添加到图表中的第二条曲线列表?

这是我的函数代码:

    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 值添加到第二个曲线列表中?

最佳答案

我自己找到了一个可能的解决方案。这是我的代码更改:

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 值曲线,依此类推。

我希望这对遇到相同或类似问题的任何人有所帮助。

关于c# - 如何使用 C# 在双 Y 轴 ZedGraph 图中添加实时数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3478482/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com