Search code examples
c#wpfchartsinvalidationoxyplot

Oxyplot updating data after the end of method


Could you please tell me why the chart is updated after the last iteration (i = 99)?

    private void music_play_button_Click(object sender, RoutedEventArgs e)
    {
        for (int i = 0; i < 100; i++)
        {
            (hr_plot.Model.Series[0] as LineSeries).Points[0] = new DataPoint(i, HRConstants.HRMin);
            (hr_plot.Model.Series[0] as LineSeries).Points[1] = new DataPoint(i, HRConstants.HRMax);
            System.Threading.Thread.Sleep(10);
            hr_plot.Model.InvalidatePlot(true);
        };
    }

The chart should change after every iteration, not after the whole loop. What is the proper solution?


Solution

  • The Buttoneventhandler blocks the UI-Thread while computing the new data points. As consequence, the chart only chances once the eventhandler is finished

    Solution: You could create a new dispatchertimer in your eventhandler and caluclate a single iteration on every timerTick