I'm trying to use OxyPlot to generate a simple chart, and display it in a ContentPage both for Android and iOS.
I created a ContentPage with the code below:
using OxyPlot;
using OxyPlot.Axes;
using OxyPlot.Series;
using System;
using Xamarin.Forms;
namespace Xamarin_App_02.Pages
{
public class GraficoPage : ContentPage
{
public GraficoPage()
{
this.Title = "Gráfico";
this.Icon = "Icon.png";
PlotModel myModel = 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));
}
myModel.Series.Add(ls);
myModel.Axes.Add(new LinearAxis(AxisPosition.Left, -4, 4));
myModel.Axes.Add(new LinearAxis(AxisPosition.Bottom));
this.Content = new StackLayout
{
Spacing = 20,
Padding = 10,
VerticalOptions = LayoutOptions.Center,
Children =
{
myModel
}
};
}
}
}
But i'm getting the following error:
cannot convert from 'OxyPlot.PlotModel' to 'Xamarin.Forms.View'
How can I convert or encapsulate the PlotModel myModel
in a View?