.net chart clear and re-add

2019-02-16 10:27发布

问题:

I have a chart and I need to clear it in order to populate it with different values. The chart has 3 series, all defined in the .aspx page.

The problem is when I call

chart.Series.Clear();

and then re-add the series like:

chart.Series.Add("SeriesName");

It doesn't keep any of the attributes of the 3 initial series. How to just clear the values and keep the series attributes?

回答1:

This should work:

foreach(var series in chart.Series) {
    series.Points.Clear();
}


回答2:

This will actually completely remove the series from the chart (not just remove the points from the series).

while (chart1.Series.Count > 0) { chart1.Series.RemoveAt(0); }


回答3:

This should work

 chartnameHERE.Series["SeriesNameHERE"].Points.Clear();