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

Dataseries add async

2 Answers 95 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
As
Top achievements
Rank 1
As asked on 31 Jul 2013, 03:02 PM
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 Answers, 1 is accepted

Sort by
0
Petar Marchev
Telerik team
answered on 02 Aug 2013, 08:01 AM
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 >>
0
EM
Top achievements
Rank 1
answered on 07 Aug 2013, 06:00 PM
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.

Tags
ChartView
Asked by
As
Top achievements
Rank 1
Answers by
Petar Marchev
Telerik team
EM
Top achievements
Rank 1
Share this question
or