Multiple LineSeries bindings in OxyPlot

Is it possible to link the plot to the LineSeries collection, and not to one LineSeries in OxyPlot? (and not through the model).

I am looking for something like this:

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

Where is myCollectionOfLineSeries:

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

I expect an answer: a) "No, this is impossible" or b) "Yes, just put XYZ before IJK."

Thanks for reading.

+3
c # plot wpf oxyplot
source share
2 answers

It may be a little late, but lately I have been asking the same question: I need to build several rows dynamically (several yield curves based on user-selected currencies), but I do not want to directly link Plot using PlotModel , as others properties (e.g. Title ) should be set in my view model as code instead of XAML markup.

So, I defined the PlotModel resource as a resource, PlotModel it to the plot. And look at PlotModel when the view is loaded. Thanks to this approach, I can define visual materials (for example, Title, Axes, Legend, etc.) using the XAML markup, and also put the logic for generating the series in my view model code.

Not sure if this is a good way, but it solves my problem.

1) XAML - define a resource

 <UserControl.Resources> <oxyPlot:PlotModel x:Key="TestPlotModel" Title="XXX Curves (Preview)" Subtitle="Scroll mousewheel to zoom; Right-drag to pan" LegendPlacement="Outside" LegendBorder="{x:Static Member=oxyPlot:OxyColors.Black}" > <oxyPlot:PlotModel.Axes> <axes:LinearAxis Title="Rate (%)" Position="Left" StartPosition="0" StringFormat="#.00000" MajorGridlineStyle="Solid" MajorGridlineColor="{x:Static Member=oxyPlot:OxyColors.LightGray}" MinorGridlineStyle="Dot" MinorGridlineColor="{x:Static Member=oxyPlot:OxyColors.LightGray}" > </axes:LinearAxis> <axes:LinearAxis Title="Maturity (Days)" Position="Bottom" StartPosition="0" MajorGridlineStyle="Solid" MajorGridlineColor="{x:Static Member=oxyPlot:OxyColors.LightGray}" > </axes:LinearAxis> </oxyPlot:PlotModel.Axes> </oxyPlot:PlotModel> </UserControl.Resources> 

2) XAML - Plot

 <oxy:Plot Grid.Row="1" Model="{Binding Source={StaticResource TestPlotModel}}"> </oxy:Plot> 

3) View the model - get the model from view, but do not snap

 protected override void OnViewLoaded(object view) { base.OnViewLoaded(view); this._model = (PlotModel)((XXXView)view).FindResource("TestPlotModel"); } 

4) View Model - Create Multiple Series

 _model.Series.Clear(); foreach (var currency in distinctCurrencies) { IEnumerable<DataPoint> dataPoints = ...; LineSeries lineSeries = new LineSeries() { Title = String.Format("*{0}", currency), ItemsSource = dataPoints }; _model.Series.Add(lineSeries); } 

hope this helps!

+6
source share

Yes, look at examples , you need to bind to a DataPoint collection

 public ObservableCollection<DataPoint> MyCollection { ... } 

and

 <oxy:Plot.Series> <oxy:LineSeries ItemsSource="{Binding MyCollection}" DataFieldX="X" DataFieldY="Y"/> </oxy:Plot.Series> 

The Series property on the Chart Type has no settings:

 public Collection<Series> Series { get { return this.series; } } 

You can bind to the Model property, which is a PlotModel type that has the Series collection property using getter and setter. See SimpleDemo for more details.

 <oxy:Plot Model="{Binding MyModel}" ... 
+1
source share

All Articles