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:
ChartData is just a simple class:
In the constructon of the class, after InitializeComponent() call, I am setting the itemSource as follows:
And finally here is the code snippet that adds a new series to the chart:
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
public List<ObservableCollection<ChartData>> _dataPointsCollection = new List<ObservableCollection<ChartData>>(); |
ChartData is just a simple class:
public class ChartData |
{ |
public DateTime XValue { get; set; } |
public double YValue { get; set; } |
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