Can you "play" a dataset?

8 posts, 0 answers
  1. Terry
    Terry avatar
    19 posts
    Member since:
    Feb 2014

    Posted 06 Mar 2014 Link to this post

    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.
  2. Martin
    Admin
    Martin avatar
    1099 posts

    Posted 11 Mar 2014 Link to this post

    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.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Terry
    Terry avatar
    19 posts
    Member since:
    Feb 2014

    Posted 23 Mar 2014 in reply to Martin Link to this post

    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.   
                  
  5. Martin
    Admin
    Martin avatar
    1099 posts

    Posted 26 Mar 2014 Link to this post

    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.

     
  6. Terry
    Terry avatar
    19 posts
    Member since:
    Feb 2014

    Posted 01 Apr 2014 in reply to Martin Link to this post

    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.

  7. Terry
    Terry avatar
    19 posts
    Member since:
    Feb 2014

    Posted 02 Apr 2014 in reply to Terry Link to this post

    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.
  8. Terry
    Terry avatar
    19 posts
    Member since:
    Feb 2014

    Posted 17 Apr 2014 in reply to Martin Link to this post

    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?
  9. Terry
    Terry avatar
    19 posts
    Member since:
    Feb 2014

    Posted 18 Apr 2014 in reply to Terry Link to this post

    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);
Back to Top
UI for WPF is Visual Studio 2017 Ready