0

I am trying to create a rolling graph using zedgraph. I used the code given in the website http://zedgraph.dariowiz.com/index3061.html . It is working properly. The graph in the sample has been implemented using curveitem as follows:

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);  

I tried to create second curve by appending the following code:

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); }

Now the question is how to create a second LineItem?

If I type: LineItem ^curve1 = dynamic_cast(zedGraphControl2->GraphPane->CurveList[1]); it shows an error during debug, saying CurveList[1] does not exist.

PeskyGnat
  • 2,454
  • 19
  • 22

1 Answers1

0

Before you can access zedGraphControl2->GraphPane->CurveList[1] (as it does not exist yet), you will need to add it first using the AddCurve() method on the GraphPane object.

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

This will also return the newly created curve which you can assign to curve1.

PeskyGnat
  • 2,454
  • 19
  • 22