饼状图MPAndroidChart

 MPAndroidChart使用也可以看我前几篇文章

1.横向双值柱状图

2.渐变色双值柱状图MPAndroidChart

 直接看图:

具体怎么时使用MPAndroidChart可已看代码

直接上代码:

初始化

 pieChart.setNoDataText("暂无数据");
        pieChart.setUsePercentValues(true);
        pieChart.getDescription().setEnabled(false);
        pieChart.setDragDecelerationFrictionCoef(0.95f);
        pieChart.setExtraOffsets(5, 10, 5, 5);
//        pieChart.setExtraBottomOffset(10);
//        pieChart.setExtraOffsets(0, 0, 0, 0);
//        holder.pieChart.setCenterText("ABC");
        pieChart.setDrawEntryLabels(false);

        pieChart.setDrawHoleEnabled(true);
        pieChart.setHoleColor(Color.WHITE);
        pieChart.setDrawCenterText(false);//饼状图中间可以添加文字

        pieChart.setHoleRadius(80f);
        pieChart.setTransparentCircleRadius(0f);
        pieChart.setRotationAngle(0);
        pieChart.animateY(1400, Easing.EaseInOutQuad);

        Legend l =  pieChart.getLegend();
        l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
        if(type==1) {
            l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
        }else{
            l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
        }
        l.setOrientation(Legend.LegendOrientation.VERTICAL);
        l.setDrawInside(false);
        l.setXEntrySpace(5f);
        l.setYEntrySpace(0f);
        l.setYOffset(10f);

        // entry label styling
        pieChart.setEntryLabelColor(Color.WHITE);
//        holder.pieChart.setEntryLabelTypeface(tfRegular);
        pieChart.setEntryLabelTextSize(12f);

绑定数据

 ArrayList<PieEntry> entries = new ArrayList<>();
        PieDataSet dataSet = new PieDataSet(entries, "");
        dataSet.setSliceSpace(3f);

        ArrayList<Integer> colors = new ArrayList<>();

        for (int i = 0; i < values.size(); i++) {
            entries.add(new PieEntry((float)values.get(i),datas.get(i)));
            colors.add(resources.getColor(Constants.COLORS_ARRAY[i]));
        }

        dataSet.setColors(colors);
        dataSet.setValueTextColor(Color.TRANSPARENT);

        PieData pieData = new PieData(dataSet);
        pieData.setValueFormatter(new PercentFormatter(new DecimalFormat()));
        pieChart.setData(pieData);
        pieChart.notifyDataSetChanged();
        pieChart.invalidate();

关于MPAndroidChart使用可以看我前几篇关于横向双值柱状图文章
 

如果对你有帮助可以关注一下方便查看,欢迎关注讨论

1.横向双值柱状图

2.渐变色双值柱状图MPAndroidChart

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值