Reputation: 1935
I am using MPAndroidChart.
I want to remove percent values on the PieChart. How can I do this?
Upvotes: 5
Views: 5410
Reputation: 11
Have a look at the code bellow
PieEntry pe1 = new PieEntry(float_percent, stingdata);
entries.add(pe1);
total_values = total_values + float_percent;
No 2:
PieData data = new PieData(dataSet);
data.setValueFormatter(new MyValueFormatter(chart));
chart.setUsePercentValues(true);
enter code here
No 3:
class MyValueFormatter extends ValueFormatter
{
public DecimalFormat mFormat;
private PieChart pieChart;
public MyValueFormatter() {
mFormat = new DecimalFormat("###,###,##0.0");
}
// Can be used to remove percent signs if the chart isn't in percent mode
public MyValueFormatter(PieChart pieChart) {
this();
this.pieChart = pieChart;
}
@Override
public String getFormattedValue(float value) {
return mFormat.format(((total_values * value)/100)) + " %";
}
@Override
public String getPieLabel(float value, PieEntry pieEntry) {
if (pieChart != null && pieChart.isUsePercentValuesEnabled()) {
// Converted to percent
return getFormattedValue(value);
} else {
// raw value, skip percent sign
return mFormat.format(value);
}
}
}
Upvotes: 1
Reputation: 51411
For not drawing the entry-values, call:
pieData.setDrawValues(false)
For not drawing the x-values, call:
pieChart.setDrawSliceText(false)
Upvotes: 11