如何在xamarin.android中使用oxyplot创建圆环图?

时间:2016-05-09 08:53:10

标签: charts highcharts xamarin.android oxyplot

我需要创建显示类似Highcharts的图表的应用。但我没有得到任何图书馆。所以我使用oxyplot创建图表。我用这样的氧气图创建了饼图。

var plotView = new PlotView (this);
        plotView.Model = PieViewModel();

        this.AddContentView (plotView,
            new ViewGroup.LayoutParams (ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent));



        public PlotModel PieViewModel()
    {
        var 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);

        return modelP1;
    }

但是现在我需要创建带有点击监听器和点击效果的圆环图。 我怎样才能做到这一点?

先谢谢

1 个答案:

答案 0 :(得分:4)

<@> @Nisar Ahmad 使用oxyplot库查找下面的代码,用于圆环图。

    public static PlotModel Simplemodel()
    {
        var modelP1 = new PlotModel { Title = "Pie Sample1" };

        dynamic seriesP1 = new PieSeries { StrokeThickness = 2.0, InsideLabelPosition = 0.5, AngleSpan = 360, StartAngle = 0, InnerDiameter = 0.4 };

        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);

        return modelP1;

    }