我在here中关于OxyPlot的文档。但我还是有点困惑。你能看一下我所遵循的过程,看看我做的是对的吗?这些只是基于我自己的理解。
这就是我的所作所为:
在便携式应用程序项目中,我将此绘图视图添加到了我的App.cs。
public App()
{
this.MainPage = new ContentPage
{
Content = new PlotView
{
Model = new PlotModel { Title = "Hello, Forms!" },
VerticalOptions = LayoutOptions.Fill,
HorizontalOptions = LayoutOptions.Fill,
},
};
}
在我的XAML页面中,我添加了此命名空间声明:
的xmlns:氧基= “CLR-名称空间:OxyPlot.Xamarin.Forms;装配= OxyPlot.Xamarin.Forms”
然后我在同一页面上添加了这个。
<oxy:PlotView Model="{Binding Model1}" VerticalOptions="Center" HorizontalOptions="Center" />
这是整个SalesPage.xaml
的代码<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:oxy="clr-namespace:OxyPlot.Xamarin.Forms;assembly=OxyPlot.Xamarin.Forms"
xmlns:ViewModels="clr-namespace:XamarinFormsDemo.ViewModels;assembly=XamarinFormsDemo"
x:Class="XamarinFormsDemo.Views.SalesPage"
BackgroundImage="bg3.jpg"
Title="Sales Page">
<ContentPage.BindingContext>
<ViewModels:SalesVM/>
</ContentPage.BindingContext>
<oxy:PlotView Model="{Binding Model1}" VerticalOptions="Center" HorizontalOptions="Center"/>
</ContentPage>
之后,我尝试调用我的视图模型,其中包含名为 PiewViewModel.cs
的图表内容using OxyPlot;
using OxyPlot.Series;
namespace ExampleLibrary
{
public class PieViewModel
{
private PlotModel modelP1;
public PieViewModel()
{
modelP1 = new PlotModel { Title = "Pie Sample1" };
dynamic seriesP1 = new PieSeries { StrokeThickness = 2.0, InsideLabelPosition = 0.8, AngleSpan = 360, StartAngle = 0 };
seriesP1.Slices.Add(new PieSlice("Africa", 1030) { IsExploded = false, Fill = OxyColors.PaleVioletRed });
seriesP1.Slices.Add(new PieSlice("Americas", 929) { IsExploded = true });
seriesP1.Slices.Add(new PieSlice("Asia", 4157) { IsExploded = true });
seriesP1.Slices.Add(new PieSlice("Europe", 739) { IsExploded = true });
seriesP1.Slices.Add(new PieSlice("Oceania", 35) { IsExploded = true });
modelP1.Series.Add(seriesP1);
}
public PlotModel Model1
{
get { return modelP1; }
set { modelP1 = value; }
}
}
}
这是我的Android版MainActivity.cs
using System;
using Android.App;
using Android.Content.PM;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using ImageCircle.Forms.Plugin.Droid;
namespace XamarinFormsDemo.Droid
{
[Activity(Label = "XamarinFormsDemo", Icon = "@drawable/recordsicon", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
global::Xamarin.Forms.Forms.Init(this, bundle);
OxyPlot.Xamarin.Forms.Platform.Android.PlotViewRenderer.Init();
LoadApplication(new App());
ImageCircleRenderer.Init();
}
}
}
你能告诉我我做错了什么吗?图表没有出现。对像我这样的新手的任何帮助都非常感谢。非常感谢。
答案 0 :(得分:1)
您的MainActivity类需要从AndroidActivity
而不是FormsApplicationActivity