我正在尝试使用zedgraph创建滚动图。我使用了网站上给出的代码 http://zedgraph.dariowiz.com/index3061.html。它运作正常。样本中的图形已使用curveitem实现,如下所示:
if ( zedGraphControl2->GraphPane->CurveList->Count <= 0 )
return;
// Get the first CurveItem in the graph
LineItem ^curve = dynamic_cast<LineItem ^>(zedGraphControl2->GraphPane->CurveList[0]);
if(curve == nullptr)
return;
// Get the PointPairList
IPointListEdit ^list = dynamic_cast <IPointListEdit^>(curve->Points);
// 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 == nullptr)
return;
// Time is measured in seconds
double time = (Environment::TickCount - tickStart);
Output_data = CreateVariable(0);// User defined function
list->Add(time, Output_data);
LineItem ^curve1 = dynamic_cast<LineItem ^>(zedGraphControl2->GraphPane->CurveList[1]);
if(curve1 == nullptr)
return;
// Get the PointPairList
IPointListEdit ^list1 = dynamic_cast <IPointListEdit^>(curve1->Points);
// 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 ( list1 == nullptr)
return;
// Time is measured in seconds
double time = (Environment::TickCount - tickStart);
Output_data = CreateVariable(0);// User defined function
list1->Add(time, Output_data); }
现在的问题是如何创建第二个LineItem?
如果我输入: LineItem ^ curve1 = dynamic_cast(zedGraphControl2-&gt; GraphPane-&gt; CurveList [1]); 它在调试期间显示错误,表示CurveList [1]不存在。
答案 0 :(得分:0)
在您访问zedGraphControl2-&gt; GraphPane-&gt; CurveList [1](因为它尚不存在)之前,您需要首先使用GraphPane对象上的AddCurve()方法添加它。
http://zedgraph.sourceforge.net/documentation/html/M_ZedGraph_GraphPane_AddCurve_3.htm
这也将返回新创建的曲线,您可以将其指定给curve1。