Selecting A Line Series After Programmatically Removing A Different Series On The Same Chart Causes Crash

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: "Index 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?

4 Replies 1 reply marked as answer

SJ Suyamburaja Jayakumar Syncfusion Team June 29, 2020 12:53 PM UTC

 
Greetings from Syncfusion. 
 
We have tried to reproduce the reported issue and we have prepared the sample based on the provided details which is working fine at our end. Please find the testing scenarios  
·       Dynamically select the selected series and remove the same series through button click 
·       Dynamically removed the selection series in selection changed event. 
 
 
Can you please share the following details which will be helpful for us to analyze the reported issue at our end and to provide a possible solution at earlier? 
·       Please check the provided sample at your end and ensure us whether you have using the same working scenario at your end or not. 
·       If possible, can you please modify the above the reproduce the reported issue. 
 
Regards, 
Suyamburaja J. 



JM Joseph Miles June 29, 2020 01:48 PM UTC

You're code worked on my end. When I modified it to more closely match my usage, I was able to reproduce the error. I've attached your modified example.

Attachment: Getting_Started_3b159d3.zip


SJ Suyamburaja Jayakumar Syncfusion Team June 30, 2020 10:28 AM UTC

Hi Joseph Miles, 
 
Thanks for your update. 
 
We were able to reproduce the reported issue at our end and analyzing the root cause of this is issue. We will update the complete details on July 2,2020. 
  
Regards, 
Suyamburaja J 



SJ Suyamburaja Jayakumar Syncfusion Team July 2, 2020 07:46 AM UTC

Hi Joseph Miles, 
 
Thanks for your patience.  
 
On further analysis, we have resolved it through sample level by changing the SeriesSelectedIndex value to -1 before removing the series as per in below code snippet 
 
C#: 
private void RemoveSeries_Click(object sender, RoutedEventArgs e) 
        { 
            ChartSeries selectedSeries = SelectedSeries; 
            Chart.SeriesSelectedIndex = -1; 
            Chart.Series.Remove(selectedSeries); 
        } 
  
 
Regards, 
Suyamburaja J. 


Marked as answer
Loader.
Up arrow icon