.net chart clear and re-add

2019-02-16 10:11发布

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?

3条回答
老娘就宠你
2楼-- · 2019-02-16 10:26

This should work:

foreach(var series in chart.Series) {
    series.Points.Clear();
}
查看更多
时光不老,我们不散
3楼-- · 2019-02-16 10:34

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); }
查看更多
我想做一个坏孩纸
4楼-- · 2019-02-16 10:34

This should work

 chartnameHERE.Series["SeriesNameHERE"].Points.Clear();
查看更多
登录 后发表回答