简体   繁体   English

方法结束后Oxyplot更新数据

[英]Oxyplot updating data after the end of method

Could you please tell me why the chart is updated after the last iteration (i = 99)? 您能否告诉我为什么图表在上一次迭代之后更新(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. Buttoneventhandler在计算新数据点时阻止UI-Thread。 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 解决方案:您可以在事件处理程序中创建一个新的dispatchertimer,并在每个timerTick上计算一次迭代

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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