Skip to content Skip to sidebar Skip to footer

In Android How To Display Percentage In Pie Chart With Achartengine

I am using achartengine for displaying the pie chart and I have tried this :-- public class AChartEnginePieChartActivity extends Activity { private static int[] COLORS = new in

Solution 1:

Try below code hope it will help to resolve your problem:-

mSeries.add(NAME_LIST[i] + "(" +VALUES[i]+"%)", VALUES[i]);  

Solution 2:

Creating a IValueFormatter:

publicclassMyValueFormatterimplementsIValueFormatter {

private DecimalFormat mFormat;

publicMyValueFormatter() {
    mFormat = newDecimalFormat("###,###,##0.0"); // use one decimal
}

@Overridepublic String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
    // write your logic herereturn mFormat.format(value) + " %"; // e.g. append a dollar-sign
}}

And next, set your formatter to the ChartData or DataSet object:

dataSet.setValueFormatter(newMyValueFormatter());

Remember this inner class just adds % to the end of your value. For example if you want to add $, you should be using $ instead of %.

Solution 3:

If you're using MPAndroidChart for Android, then IValueFormatter is now deprecated. You need to use abstract class ValueFormatter

publicclassMyValueFormatterextendsValueFormatter {
privatefinal DecimalFormat mFormat;

publicMyValueFormatter() {
    mFormat = newDecimalFormat("###,###,##0.0"); // use one decimal
}

@Overridepublic String getFormattedValue(float value) {
    return mFormat.format(value) + " %"; // e.g. append percentage sign
}
}

and then just use it by

data.setValueFormatter(MyValueFormatter())

where data is your PieData

Post a Comment for "In Android How To Display Percentage In Pie Chart With Achartengine"