OxyPlot,不在LineSeries中的点

3

我很难让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命令了...
所以,我想尝试使用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);

但那只是在输入问题时,当然不是真正的问题...

1个回答

1

您还没有将LineSeries添加到Graph中,Graph应该是Graph1而不是GraphTry

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);
  }

希望有所帮助。

1
修改了问题。那只是打字时的失误。真正的问题是为什么OxyPlot.Wpf LineSeries没有点。 - EluciusFTW
这只是一个 WPF 的包装类,您可以使用 OxyPlot.Series.LineSeries 来绘制您的图表。http://www.oxyplot.org/doc/HelloWpf.html - SWilko
1
这只是一个非常部分的答案...好吧,我使用OxyPlot,但即使我按照上面所说的做法,我仍然无法得到一个图形。即使绑定不起作用,我在视图中难道不应该至少得到一个带有标题的“空图形”吗? - EluciusFTW
此外,示例中在Xaml的头部有一行 xmlns:oxy="http://oxyplot.codeplex.com" - 如果我这样做它就无法编译,我必须使用 xmlns:oxy="clr-namespace:OxyPlot.Wpf;assembly=OxyPlot.Wpf" ... 这是否与我无法通过nuget安装包有关,而是直接引用.dll文件(即,我从OxyPlot网页下载了文件,并手动将OxyPlot.dll和Oxyplot.Wpf.dll的.dll引用添加到我的解决方案中)? - EluciusFTW

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接