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

Problem using data binding to nested collections

4 Answers 105 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Ambar Kulkarni
Top achievements
Rank 1
Ambar Kulkarni asked on 10 May 2010, 09:57 PM
I am having problem with getting the chart series to auto-update when data binding to nested collections is used. Following the example in the documentation, I created a list of ObservableCollections:

public List<ObservableCollection<ChartData>> _dataPointsCollection = new List<ObservableCollection<ChartData>>(); 

ChartData is just a simple class:

public class ChartData  
{  
        public DateTime XValue { getset; }  
 
        public double YValue { getset; }  
 
        public ChartData()  
        {  
            XValue = DateTime.Now;  
        }  
 
        public ChartData(DateTime pTime, double pValue)  
        {  
            XValue = pTime;  
            YValue = pValue;  
        }  

In the constructon of the class, after InitializeComponent() call, I am setting the itemSource as follows:

radChart1.ItemsSource = _dataPointsCollection; 

And finally here is the code snippet that adds a new series to the chart:

ObservableCollection<ChartData> DataPoints = new ObservableCollection<ChartData>();  
_dataPointsCollection.Add(DataPoints);  
 
int currentIndex = _dataPointsCollection.Count - 1;  
 
SeriesMapping seriesMapping = new SeriesMapping();  
seriesMapping.SeriesDefinition = new SplineSeriesDefinition();  
seriesMapping.CollectionIndex = currentIndex;  
seriesMapping.SeriesDefinition.ShowItemLabels = false;  
seriesMapping.LegendLabel = chartDataProvider.LegendLabel;  
seriesMapping.ItemMappings.Add(new ItemMapping("XValue", DataPointMember.XValue));  
seriesMapping.ItemMappings.Add(new ItemMapping("YValue", DataPointMember.YValue));  
radChart1.SeriesMappings.Add(seriesMapping); 

The problem I am having is that the chart control only shows data points that are already in the ObservableCollection at the time the window that has the chart is displayed; any data that gets added after the window is displayed do not get displayed in the chart at all.

What am I doing wrong? Any help would be greatly appreciated.
Thanks

-Ambar

4 Answers, 1 is accepted

Sort by
0
Dwight
Telerik team
answered on 13 May 2010, 09:41 AM
Hello Ambar,

Please, change the data source from:
List<ObservableCollection<ChartData>>
to:
ObservableCollection<ObservableCollection<ChartData>>

Regards,
Joshua
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Ambar Kulkarni
Top achievements
Rank 1
answered on 13 May 2010, 01:34 PM
Joshua,

That did not work. The chart still does not update. The one thing that works is re-setting the ItemSource every time a new element is added to any of the ObservableCollection<ChartData>.

-Ambar
0
Dwight
Telerik team
answered on 18 May 2010, 09:28 AM
Hello Ambar,

I have personally tested that scenario and it works fine. In older version of the RadChart, though, we had some issues with updates. Can you, please, check which version of the RadChart you currently use?

Please, test your project with the latest release, and if still not working, open a support ticket (forum posts do not support attachments) and provide a project that we can debug locally.

All the best,
Joshua
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Ambar Kulkarni
Top achievements
Rank 1
answered on 18 May 2010, 12:34 PM
Joshua,

Changing

public List<ObservableCollection<ChartData>> _dataPointsCollection = new List<ObservableCollection<ChartData>>(); 

to

public RadHierarchicalObservableCollection<ObservableCollection<ChartData>> _dataPointsCollection = new RadHierarchicalObservableCollection<ObservableCollection<ChartData>>(); 

fixed the problem. By the way, I am using 2010 Q1 release.

Thanks

-Ambar
Tags
Chart
Asked by
Ambar Kulkarni
Top achievements
Rank 1
Answers by
Dwight
Telerik team
Ambar Kulkarni
Top achievements
Rank 1
Share this question
or