I have this method:
private void plotGraph(List<float> data)
{
GraphPane myPane = zedGraphControl1.GraphPane;
// Set the Titles
myPane.Title.Text = "Symulacja";
myPane.XAxis.Title.Text = "Czas";
myPane.YAxis.Title.Text = "Wartość sygnału";
myPane.XAxis.Scale.Max = 20;
myPane.YAxis.Scale.Max = 5;
myPane.YAxis.Scale.Min = -5;
PointPairList PairList = new PointPairList();
double x = 0;
for (int i = 0; i <= 1000; i++)
{
PairList.Add(x, data[i]);
x += 0.01;
}
LineItem ACurve = myPane.AddCurve("Team A", PairList, Color.Red, SymbolType.None);
zedGraphControl1.Refresh();
zedGraphControl1.AxisChange();
}
And the first time I call it everything is ok, the function plots the plot i want (the Y values of the points are from the list data). Now the second and every other time i call it, there is a new line drawn over the first one (the old one stays on the chart). I would like the old one to dissapear when a new one is plotted, what should I do to get this effect?
You have to remove the old curve first. If all you'll ever have is one curve, you would remove the curve with the label "Team A", then add the PairList to a new instance. However, if in the future you want multiple curves simultaneously, you'll need to pass in the label as a parameter to your method.
To simply remove a lone curve only each time, add the following code before the call to AddCurve. An index of -1 indicates the CurveList element does not exist.
int curveIndex = myPane.CurveList.IndexOfTag("Team A");
if (curveIndex != -1)
{
myPane.CurveList.RemoveAt(curveIndex);
}
You can remove/add any number of curves, but you have to have a tag to identify the curve that you wish to change. The tag variable will replace the "Team A" above.