4

I am struggling with several issues regarding OxyPlot in a WPF project.

First off, I can use the Plot class or the PlotView class. What is the difference between these two classes?

Ideally, I want to use data binding for the Model (or at least parts of it) and for the data.

If I use PlotView, I can use Binding for the model, something like this:

<oxy:PlotView Model="{Binding Model}"/>

If I use Plot, I can use data binding for the data, something like

<oxy:Plot>
  <oxy:Plot.Series>
    <oxy:LineSeries ItemsSource="{Binding Points}" />
  </oxy:Plot.Series>
</oxy:Plot>

I can get both of these to work, but is there a way to use Binding for both the Model and the Data?

If I use the Plot class and Binding for the data, I would at least like to use Binding for the LineColor, like this

<oxy:Plot>
  <oxy:Plot.Series>
    <oxy:LineSeries ItemsSource="{Binding Points}" 
                        DataFieldX="X" 
                        DataFieldY="Y"
                        StrokeThickness="2"
                        MarkerSize="0"
                        LineStyle="Solid"
                        Color="{Binding LineColor}"
                        MarkerType="None"/>
  </oxy:Plot.Series>
</oxy:Plot>

I can't get this to work at all. The curve is always green. My LineColor property is defined with the type OxyColor. Is this the wrong type?

I know that I have asked several questions in the same posting, but I think that they are very closely related.

Phil Jollans
  • 3,605
  • 2
  • 37
  • 50
  • Forget about the problem with binding the Color property. It works if you use OxyColorConverter, as in one of the example applications. – Phil Jollans May 18 '16 at 18:41

1 Answers1

5

First off, I can use the Plot class or the PlotView class. What is the difference between these two classes?

I think you are seeing the diference in your examples, if you want to bind to the model, you have to use oxy:PlotView. If you want to bind to LineSeries, then you will have to use oxy:Plot control.

I can get both of these to work, but is there a way to use Binding for both the Model and the Data?

No, as stated in the last sentence, you cannot bind both at the same time, but you can add lineseries to your model like this (in your example):

PlotModel model = new PlotModel();
List<DataPoint> Points = new List<DataPoint>();

LineSeries lineserie = new LineSeries
{
    ItemsSource = Points,
    DataFieldX = "x",
    DataFieldY = "Y",
    StrokeThickness = 2,
    MarkerSize = 0,
    LineStyle = LineStyle.Solid,
    Color = OxyColors.White,
    MarkerType = MarkerType.None,
};

model.Series.Add(lineserie);

Then you bind to the model, using oxy:PlotView, and that's all. If you want to modify parameters that deals with plot behaviour, you have to bind to PlotController property to (just in case, for future work).

EDIT:

Oystein Bjorke (OxyPlot creator) said this, answering both questions:

The PlotView component is now similar on all platforms, it contains only Model and Controller properties. The Plot control let you define axes, series, annotations etc. and this should only be available in XAML-based platforms.

Jeankowkow
  • 814
  • 13
  • 33
Jose
  • 1,857
  • 1
  • 16
  • 34