AndroidStudio中MPAndroidChart饼图不显示问题
创始人
2024-08-21 01:00:20
0
  1. 确认在 build.gradle 文件中已经添加了 MPAndroidChart 的依赖项:
dependencies {
    implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0'
}
  1. 确认在布局文件中添加了一个 PieChart 视图:

  1. 确认在 Activity 或 Fragment 中设置了 PieChart 数据和样式等属性:
PieChart pieChart = findViewById(R.id.pie_chart);
pieChart.setUsePercentValues(true);
pieChart.getDescription().setEnabled(false);
pieChart.setExtraOffsets(5, 10, 5, 5);
pieChart.setDragDecelerationFrictionCoef(0.95f);
pieChart.setDrawHoleEnabled(true);
pieChart.setHoleColor(Color.WHITE);
pieChart.setTransparentCircleRadius(61f);
pieChart.animateY(1000, Easing.EaseInOutCubic);
  1. 确认 PieChart 中添加了数据集并应用:
ArrayList entries = new ArrayList<>();
entries.add(new PieEntry(18.5f, "Green"));
entries.add(new PieEntry(26.7f, "Yellow"));
entries.add(new PieEntry(24.0f, "Red"));
entries.add(new PieEntry(30.8f, "Blue"));

PieDataSet dataSet = new PieDataSet(entries, "Colors");
dataSet.setSliceSpace(3f);
dataSet.setSelectionShift(5f);
dataSet.setColors(ColorTemplate.JOYFUL_COLORS);

PieData data = new PieData(dataSet);
data.setValueTextSize(10f);
data.setValueTextColor(Color.YELLOW);

pieChart.setData(data);
pieChart.invalidate();

如果以上步骤都已经确认,但是饼图仍然不显示,请检查是否没有添加设置 PieChart 数据集和应用这一步骤。

相关内容

热门资讯

玩家亲测!wpk有作弊吗,有哪... 玩家亲测!wpk有作弊吗,有哪些免费的wpk作弊码,竟然是真的有挂(有挂实锤)1. 选牌创建新账号,...
一秒答解!hhpoker怎么开... 一秒答解!hhpoker怎么开透视,wepoker脚本,总是有挂(有挂头条)1、完成有辅助插件,帮助...
推荐一款!wepoker辅助透... 推荐一款!wepoker辅助透视软件,wepoker公共底牌,总是真的有挂(有挂秘笈)进入游戏-大厅...
最新技巧!wpk是真的还是假的... 最新技巧!wpk是真的还是假的,pokemmo脚本最新版,竟然存在有挂(详细教程)1、让任何用户在无...
一起来探讨!wepoker怎么... 一起来探讨!wepoker怎么发冤家牌,aapoker怎么设置抽水,一直存在有挂(有挂攻略)1)有没...
热点推荐!拱趴大菠萝挂哪里,红... 热点推荐!拱趴大菠萝挂哪里,红龙poker作弊指令,一贯是真的有挂(有挂工具)1、拱趴大菠萝挂有没有...
揭秘攻略!hhpoker有透视... 揭秘攻略!hhpoker有透视功能吗,pokemmo脚本辅助器,原来是有挂(有挂方法);该软件可以轻...
玩家必备教程!如何下载wepo... 玩家必备教程!如何下载wepoker安装包,pokemmo辅助器脚本下载,本来是有挂(有挂透视)玩家...
科技揭秘!德州局HHpoker... 科技揭秘!德州局HHpoker透视脚本,哈糖大菠萝怎么挂,都是真的是有挂(有挂存在)1、免费辅助多个...
推荐一款!wepoker透视脚... 推荐一款!wepoker透视脚本安卓,hh poker软件,都是真的有挂(确实有挂)1、脚本辅助下载...