Dataseries add async

3 posts, 0 answers
  1. As
    As avatar
    1 posts
    Member since:
    Jul 2013

    Posted 31 Jul 2013 Link to this post

    Hi,

    First of all, thank you for the wonderful products and controls. I am getting familiarized with the code and everything has been going smoothly so far.

    My question is, is it possible to add elements to RadChart ChartArea DataSeries in an asynchronous way, so that the main UI would not be blocked during setting the variable?

    Thank you!
  2. Petar Marchev
    Admin
    Petar Marchev avatar
    968 posts

    Posted 02 Aug 2013 Link to this post

    Hi,

    Unfortunately this is a framework limitation and is not possible. When you add items to the DataSeries this actually causes the chart to add visual items, which can only happen in the UI thread in WPF. Essentially it is not possible to add UI elements without the UI thread.

    Regards,
    Petar Marchev
    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 >>
  3. UI for WPF is Visual Studio 2017 Ready
  4. EM
    EM avatar
    21 posts
    Member since:
    Oct 2006

    Posted 07 Aug 2013 Link to this post

    I'm not sure if this will help, but I ran into a very similar problem, and here's how I solved my issue:

    While there is no way around UI updates that can only run on the UI thread (this is a limitation of Windows in general, not per-se a .NET issue), I was quite successful updating data on my view model using a separate thread.  My data comes from web or database sources and can take a long time to download and post-process so I didn't want to freeze up the UI thread when this was going on.  On top of that, the data load may fail entirely in which case no update should take place.

    My worker thread doing the data load signals the viewmodel when the final data set has been computed.  It does that by setting an ItemsSource property (a collection) bound to the chart's series on the viewmodel. 

    I just had to make sure that the viewmodel property update from the work thread runs on the UI thread, which is easily done by using the Dispatcher class Invoke() method to flip the execution over to the UI thread.  Bad things happen (namely, a fatal exception) when bound data is updated outside the UI thread so Dispatcher.Invoke() is essential here.

    I ran however into a separate problem with the chart series from a rendering perspective in that once my data series on my chart was bound (and rendered) with a first set of data (which works great), rebinding the same data series to a different set of data didn't update the series' visuals correctly (in that new data points in particular didn't show and axes didn't update either).  While I didn't investigate why the series didn't update correctly on a rebind (I'm sure there is a logical explanation),  I worked around this simply by creating a new series in code behind when the data source changed, then removing the old series from the chart, and adding the new series.  The visual change is almost instant and no rendering issues occurred.

    I was thus able to dissociate the data load operations using a background thread and still get the chart to update nearly instantly from the end user's perspective as soon as the data processing was completed.

    Hope this helps,


    E.

Back to Top