3

I have a strange thing happening while using ZedGraph.

I am using the same item to add multiple curves. Like:

ZedGraph LineItem curve_3;
curve_3 = pane.AddCurve("", xx_1, yy, xxyy);

I call the above lines multiple times to add multiple points. But when I remove the curve, only the last added curve gets removed and left all stays on the pane.

this.zedGraph_RenderedTrack.GraphPane.CurveList.Remove(curve_3);

I am not finding a way that will clear all the curves added. Is there a to do it?

My actual requirement is that I have to add the different lines dynamically on the pane, but I don't need to display the label information and all of them should be plotted by a single click and removed by a single click.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
NitinG
  • 893
  • 3
  • 21
  • 38

2 Answers2

4

You are holding only the last curve in this code:

ZedGraph LineItem curve_3;
curve_3 = pane.AddCurve("", xx_1, yy, xxyy);

Use collection like List<LineItem> to remember all the curves.

List<LineItem>.foreach(r => this.zedGraph_RenderedTrack.GraphPane.CurveList.Remove(r);
)
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
opewix
  • 4,993
  • 1
  • 20
  • 42
0

If you want to remove all curves from your graph pane, simply use the CurveList.Clear() method:

this.zedGraph_RenderedTrack.GraphPane.CurveList.Clear();
Anders Gustafsson
  • 15,837
  • 8
  • 56
  • 114
  • actually i dont want to remove all but only few which i have added through curve_3. left all the data i want to keep and thus we cant use the CurveList.Clear(); – NitinG Sep 12 '12 at 12:39
  • 1
    In that case, the approach that JesseJames proposes should be the way to go: collect your added curves in a separate list and then loop through the list and remove all items from the `GraphPane.CurveList`. – Anders Gustafsson Sep 12 '12 at 12:56