我很难让 OxyPlot 在我的独立 WPF 应用程序中显示我的数据(我使用 caliburn micro,并遵循 MVVM 模式)。
所以在我的 Xaml 中,我有以下内容:
<UserControl ...
xmlns:oxy="clr-namespace:OxyPlot.Wpf;assembly=OxyPlot.Wpf">
然后
<oxy:Plot Title="Winnings of Selected Player" Model="{Binding Graph1}"/>
在我的 ViewModel 中,我似乎可以选择包含using OxyPlot;
或using OxyPlot.Wpf;
. 如果我做前者,我可以定义PlotModel
如下:
private PlotModel _graph1;
public PlotModel Graph1 {
get { return _graph1;}
set {
_graph1 = value;
Graph1.RefreshPlot(true);
}
}
public MyViewModel() {
Graph1 = new PlotModel();
var FirstSeries = new LineSeries();
FirstSeries.Points.Add(new DataPoint(1,2));
FirstSeries.Points.Add(new DataPoint(1,2));
}
但我的视图没有显示任何内容(事实上,我什至没有看到“空图”或视图中的标题)。我也尝试过将RefreshPlot
命令分散到各处...
所以,我想试试using OxyPlot.Wpf;
。然后,但是,我无法添加Points
到我LineSeries
的 - 这是我的 IntelliSense 的屏幕截图......
!(http://imageshack.com/a/img30/2441/cvqy.png)
那么如何使用 OxyPlot.Wpf 将数据填充到我的 LineSeries 中?顺便说一句,即使我在没有向 LineSeries 添加点的情况下进行编译,我仍然看不到空图。我看过的所有示例都这样做,或者他们在我不想做的 .xaml.cs 代码隐藏文件中编写代码。
编辑:正如 dellywheel 提到的,我在提问时忘记将 LineSeries 添加到上面的 PlotModel 中,所以上面的构造函数应该包含该行
Graph1.Series.Add(FirstSeries);
但这只是输入问题,而不是真正的问题......