Multiple LineSeries Binding

Jun 19, 2013 at 6:39 PM
Edited Jun 19, 2013 at 6:40 PM
Is it possible to bind a plot to a collection of LineSeries instead of a single LineSeries? (and not through the Model).

I'm looking for something like this:
   <oxy:Plot>        
        <oxy:Plot.Series>     
            <oxy:LineSeries ItemsSource="{Binding myCollectionOfLineSeries}" />              
        </oxy:Plot.Series>
    </oxy:Plot>

Where myCollectionOfLineSeries is:

private ObservableCollection<LineSeries> _myCollectionOfLineSeries ;
        public ObservableCollection<LineSeries> myCollectionOfLineSeries 
        {
            get
            {
                return _myCollectionOfLineSeries ;
            }
            set
            {
                _myCollectionOfLineSeries = value;
                OnPropertyChanged("myCollectionOfLineSeries ");

            }
        }
Coordinator
Jun 19, 2013 at 6:49 PM
No, this is not possible. You need one LineSeries for each line you want to show.
Create a PlotModel and bind the Model property or use code-behind to manipulate the Series collection more dynamically.
I am sure there are also other ways to do it in XAML only (maybe using an attached property??)
Jun 19, 2013 at 7:17 PM
Thanks for the quick answer. Someone suggested me a solution in StackOverflow but obviously it doesn't work:

http://stackoverflow.com/questions/17198926/multiple-lineseries-binding-in-oxyplot/17199040?noredirect=1#comment24910980_17199040

I'll try to do it trough the PlotModel.
Jun 20, 2013 at 12:59 PM
Hi,
I had a similar situation some months ago when I needed to "bind" a plot to a custom class which had a set of data representing plot series (mainly StairStepSeries and AreaSeries).
My solution was quite simple: I created a viewmodel which contains one property for each series (List<DataPoint>), binding (in XAML) one OxyPlot series to the corresponding property (the only limitation here is that the series are statically added in XAML but it was ok for my purposes).
To fill in the values I used a simple "SetData" method in my model with my custom class as parameter, the method assigns each "class series" to the corresponding viewmodel property and fills the series using Points.Add(DateTimeAxis.CreateDataPoint(...)) calls.
Hoping to be helpful :)
Bye!
Jun 20, 2013 at 7:57 PM
Thanks, I've managed doing that by creating an ObservableCollection<LineSeries> and then with a foreach loop I update when it's needed. (I can't do the same as you because I don't know how many Series there will be: the user will be reading a file and he must be able to "add" any number of lines to the plot for comparing them).
Jun 21, 2013 at 7:50 AM
Then maybe you should bind directly the Series property of the Plot (I don't remember if this is possible) to your collection or, as objo stated, you can assign your ObservableCollection<LineSeries> to the Series property of the PlotModel in code behind and bind the PlotModel to the Plot in XAML (or at last do everything in code).
Bye :)
Jun 21, 2013 at 1:32 PM
That's exactly what I was asking, and as objo said it's not possible right now to bind "Series" to a collection of LineSeries.