This is a migrated thread and some comments may be shown as answers.

Removing a Series/DataPoints from a series

1 Answer 210 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Brian Seay
Top achievements
Rank 1
Brian Seay asked on 27 Apr 2009, 02:51 PM
Hi 

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"
            skillBarChart.DefaultView.ChartArea.DataSeries.Add(inboundBarSeries); 
            skillBarChart.DefaultView.ChartArea.DataSeries.Add(outboundBarSeries); 
           
            
        } 
        public void PopulateSkillChart() 
        { 
 
             
 
            foreach(DataPoint dp in skillBarChart.DefaultView.ChartArea.DataSeries[0]) 
            { 
                skillBarChart.DefaultView.ChartArea.DataSeries[0].Remove(dp); 
            } 
 
            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.

Thanks

Richard

1 Answer, 1 is accepted

Sort by
0
Accepted
Vladimir Milev
Telerik team
answered on 01 May 2009, 06:45 AM
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
Tags
Chart
Asked by
Brian Seay
Top achievements
Rank 1
Answers by
Vladimir Milev
Telerik team
Share this question
or