MPCHART 饼图 新手使用

由于大部分情况下使用第三方依赖都会有二次开发的需求(Maybe)

所以,不是直接引入依赖,而是在github上直接下载master分支代码,MPChartLib文件夹作为一个model引入到自己的项目里,https://github.com/PhilJay/MPAndroidChart

一般都是先在本地项目中创建一个model,然后将代码copy过去,然后全局替换一下lib名就可以了,到时候需要调整什么,直接在本地调整就可以了

使用的时候:

<xxx.xxx.mpchartlib.charting.charts.PieChart
android:layout_width="@dimen/dp_350"
android:layout_height="@dimen/dp_350"
android:id="@+id/pic_chart"
>
</xxx.xxx.mpchartlib.charting.charts.PieChart>


        // 设定label的颜色
        pieChart.setEntryLabelColor(Color.parseColor("#9e9e9e"));

        // 和四周相隔一段距离,显示数据
        pieChart.setExtraOffsets(20, 5, 20, 5);

       // 设置value的颜色
        pieData.setValueTextColor(Color.parseColor("#FFB452"));

  

        // 显示图例,设定方向为 VERTICAL 显示
        Legend legend = pieChart.getLegend();
        legend.setEnabled(true);
        legend.setOrientation(Legend.LegendOrientation.VERTICAL);

  

// 调整offsets 各个方向
pieChart.setExtraOffsets(20, 5, 20, 5);



posted @ 2021-06-23 15:37  人间春风意  阅读(403)  评论(0)    收藏  举报