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

Chart Refreshing Errors

1 Answer 101 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Alan
Top achievements
Rank 1
Alan asked on 09 Sep 2013, 07:48 PM
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:
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 oEventArgs e)
        { 
	    RefreshTimer.Stop();

	    //Capture Data, error checking, logging
	    StatusData = temp1;		//update data
	    ForecastData = temp2;	//update data
            RefreshTimer.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

1 Answer, 1 is accepted

Sort by
0
Petar Kirov
Telerik team
answered on 13 Sep 2013, 06:46 AM
Hi Alan,

So far we haven't had reports for this exception. It is hard for us to tell what may cause it without being able to reproduce it. What most likely seams to be the culprit is the async updates that you are performing in your ViewModel.

As a recommendation, I can suggest leaving the data retrieval code async, but making the update code synchronous.

It would be most helpful if you could provide a small runable project that reproduces the issue, so we can investigate it locally and track it down. Perhaps if the timer interval is really small (say 1ms) the exception would occur more often.
 

Regards,
Petar Kirov
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF. 
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>

Tags
ChartView
Asked by
Alan
Top achievements
Rank 1
Answers by
Petar Kirov
Telerik team
Share this question
or