Chart Refreshing Errors

2 posts, 0 answers
  1. Alan
    Alan avatar
    3 posts
    Member since:
    Aug 2013

    Posted 09 Sep 2013 Link to this post

    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()
                vm = new SystemStatusChartViewModel();
                DataContext = vm;
                MainWindow.CloseDataContext += MainWindow_CloseDataContext;
            void MainWindow_CloseDataContext()
                vm = (SystemStatusChartViewModel)DataContext;
                if (vm != null)
                    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)
    	    //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);             }         }

  2. Petar Kirov
    Petar Kirov avatar
    425 posts

    Posted 13 Sep 2013 Link to this post

    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.

    Petar Kirov
    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 >>

Back to Top