简体   繁体   English

OxyPlot,点不在LineSeries中

[英]OxyPlot, Points not in LineSeries

I have a hard time getting OxyPlot to display my data in my standalone WPF application (I use caliburn micro, and follow the MVVM pattern). 我很难让OxyPlot在独立的WPF应用程序中显示我的数据(我使用caliburn micro,并遵循MVVM模式)。

So in my Xaml I have the following: 所以在我的Xaml中,我有以下内容:

<UserControl ...
xmlns:oxy="clr-namespace:OxyPlot.Wpf;assembly=OxyPlot.Wpf">

and later 然后

<oxy:Plot Title="Winnings of Selected Player" Model="{Binding Graph1}"/>

In my ViewModel, I seem to have the choice to either include using OxyPlot; 在我的ViewModel中,我似乎可以选择using OxyPlot; or using OxyPlot.Wpf; using OxyPlot.Wpf; . If I do the former, I can define my PlotModel as follows: 如果使用前者,则可以如下定义我的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));

}

but my view does not display anything (in fact, I don't even see an 'empty graph', or the title in the view). 但我的视图没有显示任何内容(实际上,我什至看不到“空图”或视图中的标题)。 I have tried scattering the RefreshPlot command all over the place, too ... 我也尝试在整个地方分散RefreshPlot命令...

So then, I figure to try using OxyPlot.Wpf; 因此,我想尝试using OxyPlot.Wpf; instead. 代替。 Then, however, I cannot add Points to my LineSeries - here's a screenshot of my IntelliSense ... 然后,但是,我无法将Points添加到LineSeries -这是我的IntelliSense的屏幕截图...

!( http://imageshack.com/a/img30/2441/cvqy.png ) !( http://imageshack.com/a/img30/2441/cvqy.png

So how do I populate data into my LineSeries using OxyPlot.Wpf? 那么,如何使用OxyPlot.Wpf将数据填充到LineSeries中? By the way, I still don't see an empty graph, even when I compile without adding points to the LineSeries. 顺便说一句,即使我在未向LineSeries添加点的情况下进行编译,我仍然看不到空图。 All examples I have looked at do this, or they write code in tha .xaml.cs code-behind file which I don't want to do. 我看过的所有示例都执行此操作,或者他们在我不想执行的.xaml.cs代码隐藏文件中编写代码。

EDIT: As dellywheel mentiones, I forgot to add the LineSeries to my PlotModel above when asking the question, so the constructor above should contain the line 编辑:正如dellywheel所提到的,当我问问题时,我忘记将LineSeries添加到上述PlotModel中,因此上述构造函数应包含该行

Graph1.Series.Add(FirstSeries);

But that was just in typing the question, ofc not the real problem ... 但这只是在输入问题,不是真正的问题...

You havent added the LineSeries to the Graph and the Graph is Graph1 not Graph Try 您尚未将LineSeries添加到图,并且图是Graph1而不是Graph试试

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

Hope that helps 希望能有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM