Removing a Series/DataPoints from a series

2 posts, 1 answers
  1. Brian Seay
    Brian Seay avatar
    4 posts
    Member since:
    Aug 2012

    Posted 27 Apr 2009 Link to this post


    I'm working with the WPF controls and trying to build an application to display call data on a screen.

    My screen has 2 charts, the first of which is a line graph showing call volume over time.   In this, I add a new data point to a series as the day progresses - this works OK.

    The second chart is a summary of all calls by a business area.   Therefore, it is possible that all the data points on this chart could change.  Therefore I would either need to refresh or remove and add the data points.  I cannot find anything in documentation or examples to suggest how this could be done.

    There seems to be a Remove() method on the DataSeries object, but this takes a DataPoint object - so therefore I wrote code to enumerate the data points in a series and attempt to remove them :

               DataSeries inboundBarSeries = new DataSeries(); 
                DataSeries outboundBarSeries = new DataSeries(); 
                inboundBarSeries.Definition = new BarSeriesDefinition(); 
                outboundBarSeries.Definition = new BarSeriesDefinition(); 
                inboundBarSeries.Label = "Inbound"
                outboundBarSeries.Label = "Outbound"
            public void PopulateSkillChart() 
                foreach(DataPoint dp in skillBarChart.DefaultView.ChartArea.DataSeries[0]) 
                DataSeries inboundBarSeries = skillBarChart.DefaultView.ChartArea.DataSeries[0]; 
                DataSeries outboundBarSeries = skillBarChart.DefaultView.ChartArea.DataSeries[1]; 
                this.loadInboundSkillChart(inboundBarSeries, outboundBarSeries); 

    The first chunk of code runs once when the screen is initialised, and adds the empty series to the chart.  The PopulateSkillChart code then runs on a periodic basis and is intended to remove the data points and re-add them.  However this code fails with "Collection was modified; enumeration operation may not execute." when I try and execute it.

    Would this be recommended as a way to refresh the data set or is there an easier method which I am missing?

    I would appreciate your help on this.



  2. Answer
    Vladimir Milev
    Vladimir Milev avatar
    1061 posts

    Posted 01 May 2009 Link to this post

    Hi Brian Seay,

    The error you are getting is because you cannot modify a collection inside a foreach loop. The easiest way to clear the data series from RadChart is simply to call: skillBarChart.DefaultView.ChartArea.DataSeries.Clear();

    All the best,
    Vladimir Milev
Back to Top