I've been working with a chart and I've been running into a number of binding issues. The current exception I'm getting is
"Cannot modify the data points that belong to a databound ChartSeries instance."
at Telerik.Charting.ChartSeriesModel.OnDataPointsModified() in c:\TB\221\WPF_Scrum\Release_WPF\Sources\Development\Controls\Chart\Engine\Series\ChartSeriesModel.cs:line 89
I'm using an MVVM programming model where the VM utilizes a timer to refresh all the chart data every 30 seconds. All the items I'm binding to are Observable Collections. The chart will operate over several hours without problem but running over the course of a few days the chart will crash. I need to be able to run the application continuously without crashing.
Here is my view:
The view model is relatively long so I've made an abbreviated version. This should give you an idea of what I'm doing.
-Alan
"Cannot modify the data points that belong to a databound ChartSeries instance."
at Telerik.Charting.ChartSeriesModel.OnDataPointsModified() in c:\TB\221\WPF_Scrum\Release_WPF\Sources\Development\Controls\Chart\Engine\Series\ChartSeriesModel.cs:line 89
I'm using an MVVM programming model where the VM utilizes a timer to refresh all the chart data every 30 seconds. All the items I'm binding to are Observable Collections. The chart will operate over several hours without problem but running over the course of a few days the chart will crash. I need to be able to run the application continuously without crashing.
Here is my view:
public partial class SystemStatusChart : UserControl { public SystemStatusChart() { InitializeComponent(); vm = new SystemStatusChartViewModel(); DataContext = vm; MainWindow.CloseDataContext += MainWindow_CloseDataContext; } void MainWindow_CloseDataContext() { vm = (SystemStatusChartViewModel)DataContext; if (vm != null) { vm.RefreshTimer.Stop(); vm = null; DataContext = null; } } private SystemStatusChartViewModel vm; }
The view model is relatively long so I've made an abbreviated version. This should give you an idea of what I'm doing.
class SystemStatusChartViewModel : ViewModelBase { public Timer RefreshTimer; public SystemStatusChartViewModel() { RefreshTimer = new Timer(); RefreshTimer.Elapsed += DataService; RefreshTimer.Interval = 1000; RefreshTimer.Enabled = true; } public async void DataService(object o, EventArgs e) {RefreshTimer.Stop();//Capture Data, error checking, logging StatusData = temp1; //update data ForecastData = temp2; //update dataRefreshTimer.Start(); } /// <summary> /// The <see cref="StatusData" /> property's name. /// </summary> public const string StatusDataPropertyName = "StatusData"; private RadObservableCollection<StatusChartItem> _statusData = new RadObservableCollection<StatusChartItem>(); /// <summary> /// Sets and gets the StatusData property. /// Changes to that property's value raise the PropertyChanged event. /// </summary> public RadObservableCollection<StatusChartItem> StatusData { get { return _statusData; } set { if (_statusData == value) { return; } RaisePropertyChanging(StatusDataPropertyName); _statusData = value; LastUpdate = new ObservableCollection<DateTime>() { DateTime.Now }; FirstUpdate = new ObservableCollection<DateTime>() { DateTime.Now.AddDays(-2) }; RaisePropertyChanged(StatusDataPropertyName); } } /// <summary> /// The <see cref="ForecastData" /> property's name. /// </summary> public const string ForecastDataPropertyName = "ForecastData"; private RadObservableCollection<StatusChartItem> _forecastDataList = new RadObservableCollection<StatusChartItem>(); /// <summary> /// Sets and gets the "ForecastData property. /// Changes to that property's value raise the PropertyChanged event. /// </summary> public RadObservableCollection<StatusChartItem> ForecastData { get { return _forecastDataList; } set { if (_forecastDataList == value) { return; } RaisePropertyChanging(ForecastDataPropertyName); _forecastDataList = value; RaisePropertyChanged(ForecastDataPropertyName); } }
-Alan