2017-05-24 129 views
0

我一直在关注此优秀教程,发现here以了解如何在跟随MVVC时使用OxyPlot创建LineSeries绘图。我也下载了一些错误修正后,设法获得了本教程的作者的源代码以编译和运行。 Github上的源代码可以找到here创建Oxyplot PlotModel,可自动更新输入的新数据

不幸的是,当代码运行并创建图表时,图表不会每5秒更新一次。这是图表在我的机器上永远保持的状态。它不更新:

enter image description here

这是它应该是什么样子,更地块应显示随着时间的增加:enter image description here

现在,我已经做了我自己的一些挖掘,找出为什么它没有更新。我已经添加了一些调试命令来寻找新的点是否正确添加,如下图所示: enter image description here

我检查了的UpdateModel被称为每隔5秒,并测量正确的GetUpdateData回来,那lineSerie 。在功能结束之前,点数正在增加。 InvalidatePlot也在实际的View类中被调用。

我还能做些什么来解决这个问题吗?谢谢

+0

当数据更新时,您是否调用OnPropertyChanged? –

+0

是的,但一开始只有一次,而不是之后数据每5分钟更新一次。这与教程项目 – Mantracker

+0

中的行为相同Oxyplot需要知道数据何时发生变化,也许您必须每次都调用,而不仅仅是开始。你试过了吗? –

回答

0

我想通了。在我的XAML文件

<Window.DataContext> 
    <local:MainViewModel/> 
</Window.DataContext> 

:根据this tutorial here(创建视图部分),我想我不得不把。但根据教程项目,你不需要它:

<Window x:Class="OxyPlotDemo.MainWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:oxy="http://oxyplot.org/wpf" 
    Title="MainWindow" Height="350" Width="525"> 
<Grid> 
    <oxy:PlotView x:Name="Plot1" Model="{Binding PlotModel}" Margin="10" Grid.Row="1"> 
    </oxy:PlotView> 
</Grid> 

卸下local.MainViewModel线固定的问题。我认为它使用了错误的PlotModel,而不是在View类中创建的错误PlotModel