4

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();
vijay
  • 123
  • 1
  • 3
  • 15
  • Please post the code. Also, what version of MPAndroidChart you are using? – Ganesh Kumar Jul 27 '15 at 09:35
  • @ganesh,I am using libs/mpandroidchartlibrary-2-0-9.jar, Kindly see code. – vijay Jul 27 '15 at 10:00
  • What exactly you want do with the legends? Without any configuration I see the legend displayed with the color and text. – Ganesh Kumar Jul 27 '15 at 10:20
  • I want to show color- text-value format in legend. – vijay Jul 27 '15 at 10:36
  • I see that legends are shown without doing any configuration.There are lots of settings of chart in your code. Possibly something is interfering with the default behavior. – Ganesh Kumar Jul 27 '15 at 10:39
  • Dear Ganesh,Legend are already drawn in my chart,with format color-text.I just want to add values to this format.So it will look like color-text-value. eg. red - apple - 10, where 10 is quantities of apple – vijay Jul 27 '15 at 10:45

2 Answers2

16

Comment the line

data.setValueFormatter(new PercentFormatter());

Percentage will go away.

Ganesh Kumar
  • 3,220
  • 1
  • 19
  • 27
0
 try this,

          PieData data = new PieData(dataSet);

           data.setValueFormatter(new PercentFormatter() {

            @Override
            public String getFormattedValue(float value, Entry entry,int dataSetIndex, ViewPortHandler viewPortHandler) {

                return "";
            }

            @Override
            public String getFormattedValue(float value, AxisBaseaxis) {

                return "";
            }

            @Override
            public int getDecimalDigits() {

                return 0;
            }
        });
Vinoj Vetha
  • 726
  • 6
  • 8