MPAndroidChart的详细使用——PieChart饼图(一)

今天来记录一下PieChart(饼图)的简单使用!

注:本人使用的版本是MPAndroidChart-v3.0.3(如若版本不同有某些方法更新,可在评论区留言,尽我所能帮你解决!)
MPAndroidChart的详细使用——LineChart折线图(一)(简单使用)
MPAndroidChart的详细使用——LineChart折线图(二)(详细美化)
MPAndroidChart的详细使用——BarChart条形图(一)(简单使用)
MPAndroidChart的详细使用——BarChart条形图(二)(详细美化)
MPAndroidChart的详细使用——BarChart条形图组(三)(条形图组)
MPAndroidChart的详细使用——BarChart叠状条形图(四)(堆叠柱状图)
MPAndroidChart的详细使用——HorizontalBarChart横向条形图(五)(横向条形图)

效果图~

在这里插入图片描述

XML
<com.github.mikephil.charting.charts.PieChart
        android:id="@+id/pie"
        android:layout_width="match_parent"
        android:layout_height="300dp">
</com.github.mikephil.charting.charts.PieChart>
Java
public class PieChartActivity extends AppCompatActivity {
    private PieChart pie;
    List<PieEntry>list;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pie);
        pie = (PieChart) findViewById(R.id.pie);
        list=new ArrayList<>();


        list.add(new PieEntry(56,"男性"));
        list.add(new PieEntry(44,"女性"));

        PieDataSet pieDataSet=new PieDataSet(list,"");
        PieData pieData=new PieData(pieDataSet);
        pie.setData(pieData);

        pieDataSet.setColors(Color.RED,Color.BLUE);//设置各个数据的颜色

    }
}
发布了14 篇原创文章 · 获赞 18 · 访问量 3987

猜你喜欢

转载自blog.csdn.net/qq_44720366/article/details/104642780