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 数据集和应用这一步骤。

相关内容

热门资讯

今天下午"hhpok... 今天下午"hhpoker德州透视"werplan外卦神器(其实真的是有辅助工具)-哔哩哔哩1、hhp...
透视脚本"哈糖大菠萝... 透视脚本"哈糖大菠萝攻略"wepoker辅助器怎么弄(真是有辅助工具)-哔哩哔哩1、很好的工具软件,...
据权威媒体报道"aa... 据权威媒体报道"aapoker辅助插件工具"菠萝德州透视脚本(竟然是有辅助软件)-哔哩哔哩1、金币登...
相较于以往"约局吧开... 相较于以往"约局吧开挂"hh poker辅助有用吗(切实存在有辅助神器)-哔哩哔哩所有人都在同一条线...
目前来看"wepok... 目前来看"wepoker有透视底牌吗"如何下载德普之星辅助软件(切实有辅助工具)-哔哩哔哩1、如何下...
透视模拟器"哈糖大菠... 透视模拟器"哈糖大菠萝能开挂吗"wepoker透视脚本视频(确实真的是有辅助辅助器)-哔哩哔哩1、进...
网友热议"aapok... 网友热议"aapoker万能辅助器"pokemmo脚本辅助(原来真的有辅助下载)-哔哩哔哩1、每一步...
随着"德扑HHpok... 随着"德扑HHpoker有挂吗"wepoker怎么破解游戏(竟然真的有辅助工具)-哔哩哔哩1、每一步...
备受关注的"hhpo... 备受关注的"hhpoker辅助软件是真的么"wepoker怎么开辅助(真是真的有辅助辅助器)-哔哩哔...
现有说明如下"如何下... 现有说明如下"如何下载wepoker安装包"wepoker插件辅助(原来有辅助安装)-哔哩哔哩1)如...