How can i create doughnut chart using oxyplot in xamarin.android?

泪湿孤枕 提交于 2019-12-24 01:09:41

问题


I need to create app that shows chart like Highcharts. But i did't get any library for that. So i'm using oxyplot to create charts. I have create pie chart using oxyplot like this.

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

But now i need create doughnut chart with click listeners and effects on click. How can i do this?

Thanks in Advance


回答1:


@Nisar Ahmad Find the below codes using oxyplot libraries for doughnut chart.

    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;

    }


来源:https://stackoverflow.com/questions/37111422/how-can-i-create-doughnut-chart-using-oxyplot-in-xamarin-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!