我正在尝试使用 OxyPlot 来可视化时间序列,并且我正在使用注释来标记一些时间点和值级别,例如最小值/最大值等。
我想通过绑定(bind)在 WPF 中实现这一点,到目前为止,我从 Plot
开始。控制、两个轴和一个数据系列。这很好用,但我找不到将注释绑定(bind)到 ObservableCollection<Annontation>
的方法动态创建的各种注释。
<UserControl
...
xmlns:oxy="http://oxyplot.org/wpf"
...
>
<Grid>
...
<oxy:Plot>
<oxy:Plot.Axes>
<oxy:DateTimeAxis ... />
<oxy:LinearAxis ... />
</oxy:Plot.Axes>
<oxy:Plot.Series>
<oxy:StairStepSeries ... />
</oxy:Plot.Series>
<oxy:Plot.Annotations>
<!--
How do I bind to the ObservableCollection 'Annotations' in my ViewModel?
Note, 'Annotations' property isn't available directly in Plot, either.
-->
</oxy:Plot.Annotations>
</oxy:Plot>
</Grid>
</UserControl>
最佳答案
我遇到了类似的问题。只是为其他人提供答案,如何使用 OxyPlot 处理这个问题:
如果您有未知数量的注释或系列,您应该使用
<oxy:PlotView Model="{Binding PlotModel}" />
在 Xaml 和 ViewModel 上的这个属性public PlotModel PlotModel { get; set; }
在此属性上,您具有更大的灵 active 。不能设置PlotModel.Annotations
,如 LineSeries.ItemSource
,但是您可以根据需要添加和删除每次如此多的注释。
关于wpf - OxyPlot 图表中的可绑定(bind)注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52971299/