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

Real-time chart w/Multiple Series

3 Answers 196 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Jason Young
Top achievements
Rank 1
Jason Young asked on 02 Oct 2009, 03:31 PM
I have a stacked area chart set up with multiple series. The source of the data is an observable collection. When I add items to the observable collection, the chart does not update. When I bind the data directly without using multiple series, it updates fine. How can I get this working?

        private ObservableCollection<ChartPoint> _kw1;
        private ObservableCollection<ChartPoint> _kw2;

        private Timer _timer;

        void Window1_Loaded(object sender, RoutedEventArgs e)
        {
            _timer = new Timer(TimerCallback, null,TimeSpan.Zero, TimeSpan.FromSeconds(1));

            RadChart1.DefaultView.ChartArea.AxisX.IsDateTime = true;

            _kw1 = new ObservableCollection<ChartPoint>();

            _kw2 = new ObservableCollection<ChartPoint>();

            var seriesList = new List<ObservableCollection<ChartPoint>> { _kw1, _kw2 };

            var lineDefinition1 = new StackedAreaSeriesDefinition();
            var lineDefinition2 = new StackedAreaSeriesDefinition();

            var series1 = new SeriesMapping { LegendLabel = "Paint Line", CollectionIndex = 0, SeriesDefinition = lineDefinition1 };
            series1.ItemMappings.Add(new ItemMapping { DataPointMember = DataPointMember.YValue, FieldName = "Kw" });
            series1.ItemMappings.Add(new ItemMapping { DataPointMember = DataPointMember.XValue, FieldName = "Timestamp" });

            var series2 = new SeriesMapping { LegendLabel = "Fan 1", CollectionIndex = 1, SeriesDefinition = lineDefinition2 };
            series2.ItemMappings.Add(new ItemMapping { DataPointMember = DataPointMember.YValue, FieldName = "Kw" });
            series2.ItemMappings.Add(new ItemMapping { DataPointMember = DataPointMember.XValue, FieldName = "Timestamp" });

            var seriesMappings = new SeriesMappingCollection {series1, series2};

            RadChart1.SeriesMappings = seriesMappings;
            RadChart1.ItemsSource = seriesList;
        }

        private void TimerCallback(object o)
        {
            Debug.WriteLine("Updating...");

      if(!Dispatcher.CheckAccess())
      {
                Dispatcher.Invoke(new ThreadStart(() => TimerCallback(null)));
          return;
      }

            _kw1.Add(new ChartPoint{ Kw = (new Random()).Next(0, 10), Timestamp = DateTime.Now});
            _kw2.Add(new ChartPoint { Kw = (new Random()).Next(0, 10), Timestamp = DateTime.Now });
        }

3 Answers, 1 is accepted

Sort by
0
Velin
Telerik team
answered on 07 Oct 2009, 03:47 PM
Hi Jason Young,

The current version of the control does not respond to change notifications from the items within its items source. Our developers will cosider the possible ways to provide this functionality with a future version of the control.

In the meanwhile, you could use the RadHierarchicalObservableCollection<T> as a workaround. This collection will bubble all the change notifications from its items up.

Here is the code you need to change:
 //var seriesList = new List<ObservableCollection<ChartPoint>> { _kw1, _kw2 }; 
var seriesList = new RadHierarchicalObservableCollection<ObservableCollection<ChartData>> { _kw1, _kw2 }; 

Hope this will help.

All the best,
Velin
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Brad Ford
Top achievements
Rank 1
answered on 23 Dec 2009, 11:22 PM
Hi,

I have a similar request.

Could you please explain in more detail what you mean by 'Bubble up'? I basically have a intermittent feed of timestamped data which can have multiple timeseries that I need to trend.
This will be coming from another program that provides an Async data feed.

Thanks
Brad
0
Velin
Telerik team
answered on 28 Dec 2009, 03:57 PM
Hi Brad Ford,

Currently RadChart does not automatically handle change notifications coming from nested collections unless RadHieararchicalObservableCollection is used. The main purpose of this collection is to handle change notifications from its items and  raise the corresponding events of its own.

Hope this helps.

Kind regards,
Velin
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Chart
Asked by
Jason Young
Top achievements
Rank 1
Answers by
Velin
Telerik team
Brad Ford
Top achievements
Rank 1
Share this question
or