对于我的项目,我需要向我的双 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 值添加到第二条曲线列表中?