我很难让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提到的,当我问这个问题的时候,我忘了在上面的PlotModel中添加LineSeries,所以上面的构造函数应该包含下面这行。
Graph1.Series.Add(FirstSeries);
但这只是在输入问题时,ofc不是真正的问题……
发布于 2014-01-26 21:28:48
您尚未将图表添加到图表中,并且图表是Graph1而不是图表尝试
public MyViewModel(){
Graph1 = new PlotModel();
var firstSeries = new LineSeries();
firstSeries.Points.Add(new DataPoint(1, 2));
firstSeries.Points.Add(new DataPoint(1, 2));
Graph1.Series.Add(firstSeries);
}
希望这能有所帮助
https://stackoverflow.com/questions/21363715
复制相似问题