OxyPlot 在 VB.net 中未刷新
OxyPlot not refreshing in VB.net
当我 运行 遇到对数 X 轴问题时,我正在使用 Visual Studio 绘制数据图表。我现在转向了 OxyPlot,但是,我 运行 遇到了让我的数据填充的巨大问题。我从 windows 表单切换到 WPF,因此这可能是 XAML 绑定问题(不确定)。本质上,我在 VB.net 中采用了他们非常有限的示例,并且可以轻松地重现它。我正在努力解决的问题是使用 OxyPlot 重现动态绘图。到目前为止,这是我的代码:
示例:(http://docs.oxyplot.org/en/latest/getting-started/hello-wpf-vb.html)
Public Sub New()
Model = New PlotModel()
Model.Title = "Simple example"
Model.Subtitle = "using OxyPlot in VB.NET"
Dim series1 = New LineSeries()
series1.Title = "Series 1"
series1.MarkerType = MarkerType.Circle
series1.Points.Add(New DataPoint(0, 0))
series1.Points.Add(New DataPoint(10, 18))
series1.Points.Add(New DataPoint(20, 12))
series1.Points.Add(New DataPoint(30, 8))
series1.Points.Add(New DataPoint(40, 15))
Dim series2 = New LineSeries()
series2.Title = "Series 2"
series2.MarkerType = MarkerType.Square
series2.Points.Add(New DataPoint(0, 4))
series2.Points.Add(New DataPoint(10, 12))
series2.Points.Add(New DataPoint(20, 16))
series2.Points.Add(New DataPoint(30, 25))
series2.Points.Add(New DataPoint(40, 5))
Model.Series.Add(series1)
Model.Series.Add(series2)
End Sub
然后我尝试添加更多数据来模拟动态加载数据。我也知道我必须使用 invalidate() 并且 Update() 已被弃用。我在表单中添加了一个按钮,并在单击时给它另一个系列以添加到图表中。
按钮点击:
Private Sub test_Click(sender As Object, e As RoutedEventArgs) Handles test.Click
Dim series3 = New LineSeries()
series3.Title = "Series 3"
series3.MarkerType = MarkerType.Square
series3.Points.Add(New DataPoint(20, 20))
series3.Points.Add(New DataPoint(21, 21))
series3.Points.Add(New DataPoint(22, 22))
series3.Points.Add(New DataPoint(23, 23))
series3.Points.Add(New DataPoint(24, 24))
Model.Series.Add(series3)
Model.InvalidatePlot(True)
End Sub
这也是他们更新数据图的可爱参考:http://docs.oxyplot.org/en/latest/common-tasks/refresh-plot.html#examples
在您的事件处理程序中,您需要在调用 InvalidatePlot
之前将 series3
添加到您的 Model
,即
Model.Series.Add(series3);
Model.InvalidatePlot(true);
更新
此外,您需要确保您的 PlotModel 将您的更改通知视图 (XAML)。如果我使用 the example from Oxyplot documentation 作为示例(您指定的那个),我将修改代码:
Public Class MainViewModel Implements INotifyPropertyChanged
Private mmodel As PlotModel
Public Event PropertyChanged As PropertyChangedEventHandler _
Implements INotifyPropertyChanged.PropertyChanged
Public Sub New()
Model = New PlotModel()
Model.Title = "Simple example"
Model.Subtitle = "using OxyPlot in VB.NET"
Dim series1 = New LineSeries()
series1.Title="Series 1"
series1.MarkerType = MarkerType.Circle
series1.Points.Add(New DataPoint(0, 0))
series1.Points.Add(New DataPoint(10, 18))
series1.Points.Add(New DataPoint(20, 12))
series1.Points.Add(New DataPoint(30, 8))
series1.Points.Add(New DataPoint(40, 15))
Dim series2 = New LineSeries()
series2.Title="Series 2"
series2.MarkerType = MarkerType.Square
series2.Points.Add(New DataPoint(0, 4))
series2.Points.Add(New DataPoint(10, 12))
series2.Points.Add(New DataPoint(20, 16))
series2.Points.Add(New DataPoint(30, 25))
series2.Points.Add(New DataPoint(40, 5))
Model.Series.Add(series1)
Model.Series.Add(series2)
End Sub
Property Model() As PlotModel
Get
Return mmodel
End Get
Set(value As PlotModel)
mmodel = value
NotifyPropertyChanged("Model")
End Set
End Property
Private Sub test_Click(sender As Object, e As RoutedEventArgs) Handles test.Click
Dim series3 = New LineSeries()
series3.Title = "Series 3"
series3.MarkerType = MarkerType.Square
series3.Points.Add(New DataPoint(20, 20))
series3.Points.Add(New DataPoint(21, 21))
series3.Points.Add(New DataPoint(22, 22))
series3.Points.Add(New DataPoint(23, 23))
series3.Points.Add(New DataPoint(24, 24))
Model.Series.Add(series3)
Model.InvalidatePlot(True)
End Sub
End Class
当我 运行 遇到对数 X 轴问题时,我正在使用 Visual Studio 绘制数据图表。我现在转向了 OxyPlot,但是,我 运行 遇到了让我的数据填充的巨大问题。我从 windows 表单切换到 WPF,因此这可能是 XAML 绑定问题(不确定)。本质上,我在 VB.net 中采用了他们非常有限的示例,并且可以轻松地重现它。我正在努力解决的问题是使用 OxyPlot 重现动态绘图。到目前为止,这是我的代码:
示例:(http://docs.oxyplot.org/en/latest/getting-started/hello-wpf-vb.html)
Public Sub New()
Model = New PlotModel()
Model.Title = "Simple example"
Model.Subtitle = "using OxyPlot in VB.NET"
Dim series1 = New LineSeries()
series1.Title = "Series 1"
series1.MarkerType = MarkerType.Circle
series1.Points.Add(New DataPoint(0, 0))
series1.Points.Add(New DataPoint(10, 18))
series1.Points.Add(New DataPoint(20, 12))
series1.Points.Add(New DataPoint(30, 8))
series1.Points.Add(New DataPoint(40, 15))
Dim series2 = New LineSeries()
series2.Title = "Series 2"
series2.MarkerType = MarkerType.Square
series2.Points.Add(New DataPoint(0, 4))
series2.Points.Add(New DataPoint(10, 12))
series2.Points.Add(New DataPoint(20, 16))
series2.Points.Add(New DataPoint(30, 25))
series2.Points.Add(New DataPoint(40, 5))
Model.Series.Add(series1)
Model.Series.Add(series2)
End Sub
然后我尝试添加更多数据来模拟动态加载数据。我也知道我必须使用 invalidate() 并且 Update() 已被弃用。我在表单中添加了一个按钮,并在单击时给它另一个系列以添加到图表中。
按钮点击:
Private Sub test_Click(sender As Object, e As RoutedEventArgs) Handles test.Click
Dim series3 = New LineSeries()
series3.Title = "Series 3"
series3.MarkerType = MarkerType.Square
series3.Points.Add(New DataPoint(20, 20))
series3.Points.Add(New DataPoint(21, 21))
series3.Points.Add(New DataPoint(22, 22))
series3.Points.Add(New DataPoint(23, 23))
series3.Points.Add(New DataPoint(24, 24))
Model.Series.Add(series3)
Model.InvalidatePlot(True)
End Sub
这也是他们更新数据图的可爱参考:http://docs.oxyplot.org/en/latest/common-tasks/refresh-plot.html#examples
在您的事件处理程序中,您需要在调用 InvalidatePlot
之前将 series3
添加到您的 Model
,即
Model.Series.Add(series3);
Model.InvalidatePlot(true);
更新
此外,您需要确保您的 PlotModel 将您的更改通知视图 (XAML)。如果我使用 the example from Oxyplot documentation 作为示例(您指定的那个),我将修改代码:
Public Class MainViewModel Implements INotifyPropertyChanged
Private mmodel As PlotModel
Public Event PropertyChanged As PropertyChangedEventHandler _
Implements INotifyPropertyChanged.PropertyChanged
Public Sub New()
Model = New PlotModel()
Model.Title = "Simple example"
Model.Subtitle = "using OxyPlot in VB.NET"
Dim series1 = New LineSeries()
series1.Title="Series 1"
series1.MarkerType = MarkerType.Circle
series1.Points.Add(New DataPoint(0, 0))
series1.Points.Add(New DataPoint(10, 18))
series1.Points.Add(New DataPoint(20, 12))
series1.Points.Add(New DataPoint(30, 8))
series1.Points.Add(New DataPoint(40, 15))
Dim series2 = New LineSeries()
series2.Title="Series 2"
series2.MarkerType = MarkerType.Square
series2.Points.Add(New DataPoint(0, 4))
series2.Points.Add(New DataPoint(10, 12))
series2.Points.Add(New DataPoint(20, 16))
series2.Points.Add(New DataPoint(30, 25))
series2.Points.Add(New DataPoint(40, 5))
Model.Series.Add(series1)
Model.Series.Add(series2)
End Sub
Property Model() As PlotModel
Get
Return mmodel
End Get
Set(value As PlotModel)
mmodel = value
NotifyPropertyChanged("Model")
End Set
End Property
Private Sub test_Click(sender As Object, e As RoutedEventArgs) Handles test.Click
Dim series3 = New LineSeries()
series3.Title = "Series 3"
series3.MarkerType = MarkerType.Square
series3.Points.Add(New DataPoint(20, 20))
series3.Points.Add(New DataPoint(21, 21))
series3.Points.Add(New DataPoint(22, 22))
series3.Points.Add(New DataPoint(23, 23))
series3.Points.Add(New DataPoint(24, 24))
Model.Series.Add(series3)
Model.InvalidatePlot(True)
End Sub
End Class