0

我正在尝试使用 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->GraphPane->CurveList[1]); 它在调试期间显示错误,说 CurveList[1] 不存在。

4

1 回答 1

0

在您可以访问 zedGraphControl2->GraphPane->CurveList[1](因为它还不存在)之前,您需要首先使用 GraphPane 对象上的 AddCurve() 方法添加它。

http://zedgraph.sourceforge.net/documentation/html/M_ZedGraph_GraphPane_AddCurve_3.htm

这也将返回您可以分配给curve1的新创建的曲线。

于 2013-06-14T11:29:24.493 回答