WPF Example 1

The control is binding to the plot model:

<oxy:Plot Model="{Binding MyPlotModel}"/>

The PlotModel is generated in the ViewModel, and the plot is updated by raising an INotifyPropertyChanged event.

var temp = new PlotModel("Square wave");
var ls = new LineSeries("sin(x)+sin(3x)/3+sin(5x)/5+...");
int n = 10;
for (double x = -10; x < 10; x += 0.0001)
{
    double y = 0;
    for (int i = 0; i < n; i++)
    {
        int j = i * 2 + 1;
        y += Math.Sin(j * x) / j;
    }
    ls.Points.Add(new DataPoint(x, y));
}
temp.Series.Add(ls);
temp.Axes.Add(new LinearAxis(AxisPosition.Left,-4,4));
temp.Axes.Add(new LinearAxis(AxisPosition.Bottom));
MyPlotModel = temp;         // this is raising the INotifyPropertyChanged event

Last edited Feb 12, 2011 at 11:14 PM by objo, version 7

Comments

ysrinu21 Jan 2, 2014 at 4:53 AM 
Some of the error messages disappeared after fully qualifying to use OxyPlot.Series.LineSeries (instead of OxyPlot.Wpf.LineSeries)

If we have to use OxyPlot.* objects over OxyPlot.Wpf.* (LineSeries, LinearAxes, AxesPosition) then how are we using oxyplot WPF classes for WPF application?

Can't find 'Points' method on OxyPlot.Wpf.LineSeries object.

OxyPlot.PlotModel temp = new PlotModel("Square wave");
OxyPlot.Series.LineSeries ls = new OxyPlot.Series.LineSeries("sin(x)+sin(3x)/3+sin(5x)/5+...");

int n = 10;
for (double x = -10; x < 10; x += 0.0001)
{
double y = 0;
for (int i = 0; i < n; i++)
{
int j = i * 2 + 1;
y += Math.Sin(j * x) / j;
}

ls.Points.Add(new DataPoint(x, y));
}

temp.Series.Add(ls);
temp.Axes.Add(new OxyPlot.Axes.LinearAxis(OxyPlot.Axes.AxisPosition.Left, -4, 4));
temp.Axes.Add(new OxyPlot.Axes.LinearAxis(OxyPlot.Axes.AxisPosition.Bottom));
MyPlotModel = temp; // this is raising the INotifyPropertyChanged event

Also, get the error:
The name 'MyPlotModel' does not exist in the current context

Thanks,
-srinivas y.

ysrinu21 Jan 2, 2014 at 3:10 AM 
I am using Visual C# 2010 Express edition and downloaded packages using nuget command line

C:\Users\sri\Downloads>nuget.exe install oxyplot.wpf
Attempting to resolve dependency 'OxyPlot.Core'.
Installing 'OxyPlot.Core 2013.2.142.1'.
Successfully installed 'OxyPlot.Core 2013.2.142.1'.
Installing 'OxyPlot.Wpf 2013.2.142.1'.
Successfully installed 'OxyPlot.Wpf 2013.2.142.1'.

In the VS2010 project added references to OxyPlot.Wpf.dll and OxyPlot.dll
In the xaml added:
xmlns:oxy="clr-namespace:OxyPlot.Wpf;assembly=OxyPlot.Wpf"
<oxy:Plot Model="{Binding MyPlotModel}"/>

and code-behind added:
using OxyPlot;
//using OxyPlot.Axes;
using OxyPlot.Wpf;

and I get the same error as documented by user mli_codeplex

A complete solution with source code for the example would be very helpful

The 'using OxyPlot.Axes;' gives for the following line:
temp.Axes.Add(new LinearAxis(AxisPosition.Left, -4, 4));
the following error:
'LinearAxis' is an ambiguous reference between 'OxyPlot.Axes.LinearAxis' and 'OxyPlot.Wpf.LinearAxis'

I personally avoid the usage of 'var' keyword, and use fully qualified class name to be clear (to differentiate OxyPlot.* and OxyPlot.WPF.* classes for example)

How to fix the following errors:
Error 1 'OxyPlot.Wpf.LineSeries' does not contain a definition for 'Points' and no extension method 'Points' accepting a first argument of type 'OxyPlot.Wpf.LineSeries' could be found (are you missing a using directive or an assembly reference?)
Error 2 The best overloaded method match for 'System.Collections.ObjectModel.Collection<OxyPlot.Series.Series>.Add(OxyPlot.Series.Series)' has some invalid arguments
Error 3 Argument 1: cannot convert from 'OxyPlot.Wpf.LineSeries' to 'OxyPlot.Series.Series'
Error 4 'LinearAxis' is an ambiguous reference between 'OxyPlot.Axes.LinearAxis' and 'OxyPlot.Wpf.LinearAxis'
Error 5 'LinearAxis' is an ambiguous reference between 'OxyPlot.Axes.LinearAxis' and 'OxyPlot.Wpf.LinearAxis'
Error 6 The name 'MyPlotModel' does not exist in the current context


I was very excited to see the http://www.oxyplot.org/ExampleBrowser/ and it looks very promising, but I can't event get started because the given WPF example doesn't work

mli_codeplex Oct 11, 2013 at 11:09 AM 
In addition: for testing I used an empty Caliburn project.

Maybe any problem in installation and I should add some library more?

mli_codeplex Oct 11, 2013 at 11:03 AM 
Demos look beautiful!
Nuget installation doesn't work, so I downloaded package and added references to Oxyplot.dll and Oxyplot.wpf.dll

Then I try to use your example.

var ls = new LineSeries("sin(x)+sin(3x)/3+sin(5x)/5+..."); -

Error 1 'OxyPlot.Wpf.LineSeries' does not contain a constructor that takes 1 arguments

ls.Points.Add(new DataPoint(x, y)); -

Error 2 'OxyPlot.Wpf.LineSeries' does not contain a definition for 'Points' and no extension method 'Points' accepting a first argument of type 'OxyPlot.Wpf.LineSeries' could be found (are you missing a using directive or an assembly reference?)

temp.Series.Add(ls) -

Error 3 The best overloaded method match for 'System.Collections.ObjectModel.Collection<OxyPlot.Series.Series>.Add(OxyPlot.Series.Series)' has some invalid arguments

and

Error 4 Argument 1: cannot convert from 'OxyPlot.Wpf.LineSeries' to 'OxyPlot.Series.Series'

temp.Axes.Add(new LinearAxis(AxisPosition.Left, -4, 4));

Error 5 The best overloaded method match for 'System.Collections.ObjectModel.Collection<OxyPlot.Axes.Axis>.Add(OxyPlot.Axes.Axis)' has some invalid arguments

and

Error 6 Argument 1: cannot convert from 'OxyPlot.Wpf.LinearAxis' to 'OxyPlot.Axes.Axis'

and so on...

PS
using OxyPlot;
using OxyPlot.Axes;
using OxyPlot.Wpf;

alanrorr1 Oct 2, 2013 at 5:40 PM 
It may be helpful to mention that oxy should be defined at the top of the XAML file: xmlns:oxy="clr-namespace:OxyPlot.Wpf;assembly=OxyPlot.Wpf". This is since that line is not generated automatically from install (i.e. I installed OxyPlot through Nuget).