但我在互联网上找到的代码似乎并不合适。我只是想问一下如何在OxyPlot中创建一个Chart,特别是Pie Chart。从我的XAML到XAML.cs以及模型和视图模型等其他文件。
请你以某种方式向我提供一些说明或代码,或许我可以告诉我如何做到这一点?
我希望在我的SalesPage中对图表进行编码。
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"
x:Class="XamarinFormsDemo.Views.SalesPage"
xmlns:oxy="clr-namespace:OxyPlot.Xamarin.Forms;assembly=OxyPlot.Xamarin.Forms"
BackgroundImage="bg3.jpg"
Title="Sales Page">
</ContentPage>
SalesPage.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OxyPlot;
using Xamarin.Forms;
using OxyPlot.Xamarin.Forms;
namespace XamarinFormsDemo.Views
{
public partial class SalesPage : ContentPage
{
public SalesPage()
{
InitializeComponent();
}
}
}
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 :(得分:2)
有一个Oxy Plot和Xamarin.Forms here的入门指南。要回答您的问题,您可以执行以下操作:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="XamarinFormsDemo.Views.SalesPage"
xmlns:oxy="clr-namespace:OxyPlot.Xamarin.Forms;assembly=OxyPlot.Xamarin.Forms"
BackgroundImage="bg3.jpg"
Title="Sales Page">
<oxy:PieSeries ... />
</ContentPage>
有关PieSeries
here的更多文档以及使用它here的一些示例。例如:
private static PlotModel CreateExample()
{
var model = new PlotModel { Title = "World population by continent" };
var ps = new PieSeries
{
StrokeThickness = 2.0,
InsideLabelPosition = 0.8,
AngleSpan = 360,
StartAngle = 0
};
// http://www.nationsonline.org/oneworld/world_population.htm
// http://en.wikipedia.org/wiki/Continent
ps.Slices.Add(new PieSlice("Africa", 1030) { IsExploded = true });
ps.Slices.Add(new PieSlice("Americas", 929) { IsExploded = true });
ps.Slices.Add(new PieSlice("Asia", 4157));
ps.Slices.Add(new PieSlice("Europe", 739) { IsExploded = true });
ps.Slices.Add(new PieSlice("Oceania", 35) { IsExploded = true });
model.Series.Add(ps);
return model;
}