简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM