0

Is there a way, to bind the series of a OxyPlot in XAML, if I don't know, how many series I will have?

I know, that I can create a PlotModel, maybe I can bind a Collection of Series. But what I am realy looking for is, if I can bind the series to List of doubles.

Possible ItemSources examples:

ObservableCollection<Tupel<double, List<double>>> ItemSource1 { get; set; }

ObservableCollection<Tupel<double, double>> ItemSource2 { get; set; }

Possible Xaml Code:

<oxy:Plot>
 <oxy:LineSeries ItemSource="{Binding ItemSource}" />
</oxy:Plot>

I dind't find such a use case in the examples. Does someone have maybe a tipp for me?

RCP161
  • 199
  • 1
  • 13

1 Answers1

0

Is there a way, to bind the series of a OxyPlot in XAML, if I don't know, how many series I will have?

No, there isn't.

Does someone have maybe a tipp for me?

As you have already discovered, you could create a PlotModel in your view model, and bind to and add series to this one.

There is a code sample available in the official docs:

public class MainViewModel
{
    public MainViewModel()
    {
        this.MyModel = new PlotModel { Title = "Example 1" };
        this.MyModel.Series.Add(new FunctionSeries(Math.Cos, 0, 10, 0.1, "cos(x)"));
    }

    public PlotModel MyModel { get; private set; }
}

XAML:

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

If you don't want to use a PlotModel, you could create an attached behaviour that adds the series.

mm8
  • 163,881
  • 10
  • 57
  • 88
  • @RCP161: Sorry. So the answer to your question is no. I edited my answer. If you don't want to use a PlotModel, you could create an attached behaviour. But there is no pure XAML solution. – mm8 Mar 18 '19 at 12:52
  • Info: If you try to add the series to the plot, you will probably have to bind each series ItemSource to a collection. Changes on the ActualModel will have no effect, even ift it is not null. If you using the ItemSource, you are implementing the behavior of the PlotModel again. So simply use the PlotModel. – RCP161 Mar 19 '19 at 12:19