Multiple LineSeries Binding

Oystein Bjorke 6 aastat tagasi 0
This discussion was imported from CodePlex

everytimer wrote at 2013-06-19 20:39:

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:LineSeries ItemsSource="{Binding myCollectionOfLineSeries}" />              

Where myCollectionOfLineSeries is:

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


objo wrote at 2013-06-19 20:49:

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

everytimer wrote at 2013-06-19 21:17:

Thanks for the quick answer. Someone suggested me a solution in StackOverflow but obviously it doesn't work:

I'll try to do it trough the PlotModel.

DJDAS wrote at 2013-06-20 14:59:

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

everytimer wrote at 2013-06-20 21:57:

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

DJDAS wrote at 2013-06-21 09:50:

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

everytimer wrote at 2013-06-21 15:32:

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.