Deleting series on a chart based on order

Hi,

I’m trying to delete extra series from a chart based on order (rather than the default order when accessing NSeries by index). My current code is as follows:

for (int order = myChart.NSeries.Count - 1; order >= rowsWithData; order--) {
        Series series = myChart.NSeries.GetSeriesByOrder(order);
        int seriesIndex = myChart.NSeries.IndexOf(series);
        myChart.NSeries.RemoveAt(seriesIndex);
}

Is there a better way of doing this? Is there a method I can call to delete the Series object I get from calling GetSeriesByOrder?

Thanks.

@vonH Your code is correct, SeriesCollection class also contain a method Clear, but it removes all the series.

1 Like