Reputation: 10929
I am using MPAndroidChart library to make a pie chart. I would like to display the pie chart values with the decimal. I want to retain the % sign.
This solution to an old similar question is not valid since the release of version 3.0.0 of MPAndroidChart
UPDATE: This is the updated way of removing decimals
public class DecimalRemover extends DefaultValueFormatter {
private int digits;
public DecimalRemover(int digits) {
super(digits);
this.digits = digits;
}
@Override
public int getDecimalDigits() {
return digits;
}
}
But even if I did pieChart.setUsePercentValues(true);
, the "%" symbol is not being shown
Upvotes: 1
Views: 1784
Reputation: 10929
In the setData()
method:
PieData data = new PieData(dataSet);
data.setValueFormatter(new DecimalRemover(new DecimalFormat("###,###,###")));
Here is the DecimalRemover class:
public class DecimalRemover extends PercentFormatter {
protected DecimalFormat mFormat;
public DecimalRemover(DecimalFormat format) {
this.mFormat = format;
}
@Override
public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
return mFormat.format(value) + " %";
}
}
Upvotes: 4