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

Can you "play" a dataset?

7 Answers 93 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Terry
Top achievements
Rank 1
Terry asked on 07 Mar 2014, 12:03 AM
I would like to simulate a real-time sequence of events by having my RadCartesianChart update graphically as new data is received. Off the top of my head, I am thinking the best way to acheive this would be to have an Observable collection that gets updated with new data points every so often and push data  to the chart, having it refresh and thus display the new results, along with the previous results. (i.e. The collection would be growing...)

 It certainly does not have to be an Observable collection and could just as easily be rebinding the ItemSource with a new enumerable collection at some fixed time interval (i.e. the playback rate).

Is this possible with Telerik's RadCartesianChart ? Basically have the chart act as a visual display to a live-stream of dynamic data....

Thanks in advance.

7 Answers, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 11 Mar 2014, 04:19 PM
Hi Terry,

I believe our Live Data demo will be helpful for your scenario. Basically it demonstrates live streaming data which is updated in a DispatcherTimer and it's displayed in a RadCartesianChart.  You can find this example in our WPF demos under the ChartView --> Live Data section.

Regards,
Martin
Telerik

DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.

0
Terry
Top achievements
Rank 1
answered on 24 Mar 2014, 03:21 AM
Hi Martin. 

This is working for me now. Thanks for the explanation.  A few follow-up questions.

1.) The chart I am playing has a few series bound using declarative syntax, like so:
 <telerik:AreaSeries ItemsSource="{Binding MyViewData}" CategoryBinding="date" 
                                ValueBinding="myValue1" Name="myValue1Line" CombineMode="Stack"   
                                Fill="Red" Stroke="Red">
  </telerik:AreaSeries>

The data series that are declaratively bound play fine, given your explanation. However, there are a few other data series I am binding dynamically - as I do not know ahead of time what they are. I am doing this like so:

 foreach (var group in groups)
 {
                var areaSeries = new AreaSeries();
                areaSeries.CombineMode = Telerik.Charting.ChartSeriesCombineMode.Stack;
                areaSeries.ValueBinding = new PropertyNameDataPointBinding("Y");
                areaSeries.CategoryBinding = new PropertyNameDataPointBinding("X");
                areaSeries.Name = (String)((Telerik.Windows.Data.QueryableCollectionViewGroup)(group)).Key;

                areaSeries.ItemsSource = group as IEnumerable;
}

These items do no play (or are added dynamically). They just remain on the chart. Is there a way to add my dynamic items so that they can also "play" as you described below. 

A little additional information. The dynamically bound data series are expressed in the ViewModel as a one-to-many aggregation relationship. So the View Model contains a list of items that I am iterating thru and dynamically adding to the chart. Can I use declarative syntax to bind the list of items?

class MyViewModel
{
      DateTime X;
     double Y;
     List<ViewModelChildren>  children;


Can I bind children in the same chart as I bind MyViewModel?

2.) The way the playback occurs is that the X-axis/date-range grows dynamically. Is there a way to fix the date-range so that it is constant, yet drop the new points dynamically in? I want to play it so the datapoints are dynamically added within a fixed X-value date range.

Thanks.   
              
0
Martin Ivanov
Telerik team
answered on 26 Mar 2014, 03:22 PM
Hi Terry,

You can create dynamic number of series with a ChartSeriesDescriptor instead of code behind. As for the fixed date range you can use the Maximum and Minimum properties of your date time axis

For your convenience I prepared a project which demonstrates a cartesian chart with multiple AreaSeries defined with a series descriptor.

Regards,
Martin
Telerik
 

Build cross-platform mobile apps using Visual Studio and .NET. Register for the online webinar on 03/27/2014, 11:00AM US ET.. Seats are limited.

 
0
Terry
Top achievements
Rank 1
answered on 01 Apr 2014, 02:49 PM
Martin,

the demo project you attached appears to be a silverlight project. Do you have a WPF version?

ALso, I followed some online examples. Problem is I am using a datasoure like so:


<Window.DataContext>
<viewModels:MyViewModel />
</Window.DataContext>

When using a datasource, it appears that the graph is ignorng the provider source. Not every thing is dynamic. A few of the series are known ahead of time. Is there a way to add support for dynamic series without redoing the approach I have used for the remainder of the graph.

0
Terry
Top achievements
Rank 1
answered on 02 Apr 2014, 11:41 AM
Edit: You can disregard this question. I think I understand the issue. Sorry for the confusion.

Also, I do not need a WPF version of the attached project. I was able to discern the appropriate elements from the SilverLight example. Thanks.
0
Terry
Top achievements
Rank 1
answered on 17 Apr 2014, 06:53 PM
Martin wrote: "You can create dynamic number of series with a ChartSeriesDescriptor instead of code behind."

If I would like changes to the dynamic series to be displayed in the chart. I am able to load the dynamic series, but when I make changes to the underlying dataset, the changes are not reflected in the chart.

How can I do this with a dynamic series?
0
Terry
Top achievements
Rank 1
answered on 18 Apr 2014, 02:10 PM
I keep doing this....asking questions and then finding my own answers before you have time to respond. For those interested, here is how I solved it. Updating a charts series property must fire an event to redraw the series.
//create a new series
var areaSeries = new AreaSeries();
areaSeries.ValueBinding = new PropertyNameDataPointBinding("aValue");
areaSeries.CategoryBinding = new PropertyNameDataPointBinding("aDate");
areaSeries.Name = "my dynamic series name";

//modify the underlying connection and add it to the series 
            var filteredCollection = myCollection.Select(r=>r.series);             foreach (var item in filteredCollection )
{
    areaSeries.ItemsSource = item;
}

//clear and bind the area series to the chart
           myChart.Series.Clear();
myChart.Series.Add(areaSeries);
Tags
ChartView
Asked by
Terry
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Terry
Top achievements
Rank 1
Share this question
or