For an application I am building, I have a requirement that a user can select a series on the chart and remove that series from the chart. I have figured out how to remove the series (calling
Chart.Series.Remove(SelectedSeries) does the trick), however, after selecting the second or third series to remove, the application crashes with a
System.ArgumentOutOfRangeException and the following message: "I
ndex was out of range. Must be non-negative and less than the size of the collection."
The stack trace provided by Visual Studio points to SyncFusion core as the source of the exception:
at Windows.UI.Xaml.DependencyObject.SetValue(DependencyProperty dp, Object value)
at Syncfusion.UI.Xaml.Charts.ChartSelectionBehavior.OnMouseDownSelection(ChartSeriesBase series, Object value)
at Syncfusion.UI.Xaml.Charts.ChartSelectionBehavior.OnPointerReleased(PointerRoutedEventArgs e)
at Syncfusion.UI.Xaml.Charts.SfChart.OnPointerReleased(PointerRoutedEventArgs e)
I've tried a couple of other methods for removing a series from a chart, but each has had their own problems:
- Attempted to remove the series by using Chart.Series = (ChartSeriesCollection)Chart.Series.Where(series => series != SelectedSeries). Unfortunately, this lead to the application crashing with a casting error, Visual Studio reporting that the result of Where could not be cast to a ChartSeriesCollection.
- Attempted to remove the series by first removing the series data from the connected view model, then clearing all series from the chart and redrawing them. Unfortunately this lead to the same problem where attempting to select another series after deleting another causes a System.ArgumentOutOfRangeException exception to be thrown.
Is this a bug with SyncFusion? If not, how can I remove a series from a chart that has selection enabled and not have my application crash when the user selects another series?