Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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).

So in my Xaml I have the following:

<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; or using OxyPlot.Wpf;. If I do the former, I can define my PlotModel as follows:

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 ...

So then, I figure to try using OxyPlot.Wpf; instead. Then, however, I cannot add Points to my LineSeries - here's a screenshot of my IntelliSense ...

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

So how do I populate data into my LineSeries using OxyPlot.Wpf? By the way, I still don't see an empty graph, even when I compile without adding points to the 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.

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

Graph1.Series.Add(FirstSeries);

But that was just in typing the question, ofc not the real problem ...

like image 440
EluciusFTW Avatar asked Jan 01 '26 03:01

EluciusFTW


1 Answers

You havent added the LineSeries to the Graph and the Graph is Graph1 not Graph Try

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

like image 189
SWilko Avatar answered Jan 02 '26 15:01

SWilko