Reputation: 1
Hello I try to use OxyPlot in a c# .NET 8.0 MAUI application but on the UI nothing appears, not even the axes. I've tried to look for examples on the internet but all I could find were Xamarin projects. Thanks for your help in advance.
In the MainPage.xaml I have:
<ContentPage.Resources>
<local:OrientationPlotModel x:Key="orientationPlotModel"/>
</ContentPage.Resources>
And I have this inside of a Frame:
<oxy:PlotView x:Name="OrientationDiagramPlotModel" BackgroundColor="White" />
In the MainPage.xaml.cs I have:
private OrientationPlotModel orientationPlotModel;
public MainPage()
{
InitializeComponent();
orientationPlotModel=new OrientationPlotModel();
OrientationDiagramPlotModel.BindingContext = orientationPlotModel;
}
In the OrientationPlotModel.cs I have:
using OxyPlot;
using OxyPlot.Axes;
using OxyPlot.Series;
namespace MauiApp2.View
{
public class OrientationPlotModel
{
public PlotModel PlotModel { get; private set; }
private LineSeries orientationSeries;
private double[] orientationData = new double[10];
public OrientationPlotModel()
{
InitializePlotModel();
}
private void InitializePlotModel()
{
PlotModel = new PlotModel();
var bottomAxis = new LinearAxis
{
Position = AxisPosition.Bottom,
Minimum = 10,
Maximum = 100,
Title = "X Axis Title",
MajorGridlineStyle = LineStyle.Solid,
MinorGridlineStyle = LineStyle.Dot,
AxislineColor = OxyColors.Blue,
};
var leftAxis = new LinearAxis
{
Position = AxisPosition.Left,
Minimum = 0,
Maximum = 180,
Title = "Y Axis Title",
MajorGridlineStyle = LineStyle.Solid,
MinorGridlineStyle = LineStyle.Dot,
};
PlotModel.Axes.Add(bottomAxis);
PlotModel.Axes.Add(leftAxis);
orientationSeries = new LineSeries();
PlotModel.Series.Add(orientationSeries);
for (int i = 0; i < orientationData.Length; i++)
{
orientationSeries.Points.Add(new DataPoint(i, orientationData[i]));
}
}
public void UpdateOrientation(float orientation)
{
//...
}
}
}
Upvotes: 0
Views: 508