vijay vijay - 18 days ago 5
Android Question

How to show only data value instead of percents in piechart

I am using Android MPChart library in my Android project. Where I want to show only data value on pie chart.

I tried with

chart.setUsePercentValues(false);


but it shows actual value with % symbol.
I want to remove that % symbol. How to remove % symbol?

Also if possible, I would like to show data in legend.

Code for Pie Chart

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();

Answer

Comment the line

data.setValueFormatter(new PercentFormatter());

Percentage will go away.