Multi-Threading Scatter Chart

2 posts, 0 answers
  1. Alan
    Alan avatar
    1 posts
    Member since:
    Jan 2012

    Posted 01 Feb 2012 Link to this post

    Hi, Are there any examples in the documentation which show how threading with the Chart works?

    Specifically, my issue is that I have a long loop which adds "Coordinate" objects to an ObservableCollection which is set as the ItemsSource of some ScatterSeries. Assume that this loop takes minutes to complete, as I add a Thread.Sleep(1000) for each iteration. Importantly, I would like the chart to display each "Coordinate" object as and when it is added to the ObservableCollection, without seizing up the whole chart.

    I have followed some examples of creating a Dispatcher, however this appears to have no effect. Example code of what I am trying to achieve:

    private ObservableCollection<Coordinate> coordinates = new ObservableCollection<Coordinate>();
    private Queue<Coordinate> coordinatesQueue = new Queue<Coordinate>();
    private void FillQueue()
    private void UpdateChart()
        SomeScatterSeriesinChart.ItemsSource = coordinates;
            (ThreadStart) delegate()
                        while (coordinatesQueue.Count != 0)

    Thanks for any help in advanced!
  2. Giuseppe
    Giuseppe avatar
    2363 posts

    Posted 06 Feb 2012 Link to this post

    Hello Alan,

    You need to perform the data update in a BackgroundWorker thread to achieve the desired mutli-threading effect. Note, however, that if you are starting the project now, we would suggest you to consider using our new next-generation charting solution RadChartView instead as it was implemented with such scenarios in mind and works seamlessly out-of-the-box (RadChart would also work with a BackgroundWorker update but you will need to wrap the actual "update" call inside a Dispatcher.BeginInvoke(...) statement due to the specifics of the control implementation, while with RadChartView you do not need any UI hooks in your ViewModel to achieve the same effect).

    We have attached a sample application with RadChartView to get you started.

    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Back to Top