【发布时间】:2015-07-27 09:17:27
【问题描述】:
我在我的 Android 项目中使用 Android MPChart 库。我只想在饼图上显示数据值。
我试过了
chart.setUsePercentValues(false);
但它用 % 符号显示实际值。 我想删除那个 % 符号。如何去掉%符号?
如果可能的话,我想在图例中显示数据。
饼图代码
chart.setUsePercentValues(false);
chart.setHoleColorTransparent(true);
chart.setHoleRadius(60f);
chart.setDrawHoleEnabled(true);
chart.setRotationAngle(0);
chart.setRotationEnabled(true);
chart.setDescription("");
chart.setDrawSliceText(false);
PieDataSet dataSet = new PieDataSet(yVals, "");
dataSet.setSliceSpace(3f);
dataSet.setColors(colors);
/**Set data to piechart */
PieData data = new PieData(xVals, dataSet);
data.setValueFormatter(new PercentFormatter());
data.setValueTextSize(10f);
data.setValueTextColor(Color.WHITE);
chart.setData(data);
chart.setDescription("");
chart.highlightValues(null);
chart.animateXY(1500, 1500, AnimationEasing.EasingOption.EaseOutBack);
chart.setTouchEnabled(true);
Legend l = chart.getLegend();
l.setPosition(Legend.LegendPosition.RIGHT_OF_CHART);
l.setXEntrySpace(7f);
l.setYEntrySpace(5f);
chart.invalidate();
【问题讨论】:
-
请贴出代码。另外,您使用的是什么版本的 MPAndroidChart?
-
@ganesh,我正在使用 libs/mpandroidchartlibrary-2-0-9.jar,请查看代码。
-
您到底想对图例做什么?在没有任何配置的情况下,我会看到带有颜色和文本的图例。
-
我想在图例中显示颜色文本值格式。
-
我看到图例显示没有做任何配置。你的代码中有很多图表设置。可能有什么东西干扰了默认行为。