Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WPF > Chart > Multi-Threading Scatter Chart

Not answered Multi-Threading Scatter Chart

Feed from this thread
  • Alan avatar

    Posted on Feb 1, 2012 (permalink)

    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;
        this.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
            (ThreadStart) delegate()
                    {
                        while (coordinatesQueue.Count != 0)
                        {
                            coordinates.Add(coordinatesQueue.Dequeue());
                            Thread.Sleep(1000);
                        }
                    }
        );
    }


    Thanks for any help in advanced!

    Reply

  • Giuseppe Giuseppe admin's avatar

    Posted on Feb 6, 2012 (permalink)

    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.


    Greetings,
    Giuseppe
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
    Attached files

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WPF > Chart > Multi-Threading Scatter Chart
Related resources for "Multi-Threading Scatter Chart"

WPF Chart Features  |  Documentation  |  Demos  |  Telerik TV  |  Self-Paced Trainer  ]