Telerik
Skip Navigation LinksHome / Community / Forums / WPF > Chart > Removing a Series/DataPoints from a series

Answered Removing a Series/DataPoints from a series

Feed from this thread
  • Brian Seay avatar

    Posted on Apr 27, 2009 (permalink)

    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

    Reply

  • Answer Telerik Admin admin's avatar

    Posted on May 1, 2009 (permalink)

    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

    Reply

Back to Top

Skip Navigation LinksHome / Community / Forums / WPF > Chart > Removing a Series/DataPoints from a series
Related resourses for "Removing a Series/DataPoints from a series"

WPF Chart Features  |  Documentation  |  Demos  |  Telerik TV  |  Self-Paced Trainer  ]

Powered by Sitefinity ASP.NET CMS

Contact Us | Site Feedback | Terms of Use | Privacy Policy
Copyright © 2002-2010 Telerik. All rights reserved.