Android Chart框架 MPAndroidChart学习笔记8_饼图
源码demo看这里
1.设置数据
List<PieEntry> entries = new ArrayList<>();
entries.add(new PieEntry(26.7f, "Yellow"));
entries.add(new PieEntry(24.0f, "Red"));
entries.add(new PieEntry(30.8f, "Blue"));
entries.add((new PieEntry(18.5f, "Green")));
PieDataSet set = new PieDataSet(entries, "Election Results");
2.设置颜色
set.setColors(new int[]{Color.YELLOW,Color.RED,Color.BLUE,Color.GREEN});
3.装载数据
PieData data = new PieData(set);
mChart.setData(data);
mChart.invalidate();
显示如下: