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

Issue with RadCartesianChart & Databinding on background threads

2 Answers 56 Views
Chart
This is a migrated thread and some comments may be shown as answers.
James
Top achievements
Rank 1
James asked on 26 Sep 2012, 10:09 PM
I am databinding to a BarSeries for a RadCartesianChart on a background thread and I'm running into issues.  Specifically that none of my data is showing up.  If I bind the data on the main UI thread everything shows up great, but I need to bind the data in a callback from an asynchronous webservice call.  When I alter the BarSeries ItemSource in the callback, the RadCartesianChart never updates with the new information.

Is there something I am doing wrong?  How can I bind data from an asynchronous web service call to a RadCartesianChart BarSeries?

2 Answers, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 01 Oct 2012, 10:12 AM
Hello James,

The chart belongs to the UI thread and all actions that are done over it should be done from this thread. You can marshal to the UI thread using this code:

p.Dispatcher.BeginInvoke(() => {
        p.Children.Clear();
        p.Children.Add(
            new TextBlock { Text = "Added by Dispatcher." });
    });

More information is available here on MSDN.All the best,
Yavor
the Telerik team

Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.

0
James
Top achievements
Rank 1
answered on 01 Oct 2012, 01:23 PM
Thanks--I was already using the DIspatcher.  But I did manage to solve my problem--unsurprisingly it had nothing to do with the telerik control.  The problem was the data type I was using for the BasSeries.  Apparently you cannot add or remove items from a List in a background thread and expect the data binding to work properly, you have to use an ObservableColleciton.  So once I switched to an ObservableCollection I was fine.  I'm sure this is a dumb mistake but the List worked as long as the changes were done in the UI thread. 
Tags
Chart
Asked by
James
Top achievements
Rank 1
Answers by
Yavor
Telerik team
James
Top achievements
Rank 1
Share this question
or