Mpandroidchart: How to hide labels of pie part if its value is 0

Created on 19 Apr 2016  路  22Comments  路  Source: PhilJay/MPAndroidChart

I want to hide labels in some parts of pie chart when its value is 0, because I don't want to see these labels is stacked as picture bellow
bug
How do I fix it???

Most helpful comment

@son2017 Deprecated -> use setDrawEntryLabels(...) instead.

All 22 comments

just try to take the values of 0 ArrayList yVals1 = new ArrayList ();
put in this object just values more than 0.

@thadeubatista
Thanks you, it is a solution but is not best solution because if I remove a value that equal 0, it will be not showed in pie chart as picture bellow.
bug

I want user know all pies name of pie chart, so they also know that its value equal 0

ok,
It will be necessary to change the source code. Once I have a little time , I will see this improvement.

Ok, please let me know when you done it :)

I have fixed it, you can update your code to github
It's very simple, just add one line:
//draw everything, depending on settings
If(entry.getVal()>0) {
...
}
At PieChartRenderer.java file, line: 231

its not so simple. you going to need not only this place but too another place. And your solution is fixed on code and the ideal is that it be calculated properly like mChart.setEmptyXLabel(false), and so you can retriwe this variable on PieChartRenderer like this:
if(mChart.isEmptyXLabel()). This way you can use this verification in another places that need to be verified like this place let you missing:

if (drawXOutside || drawYOutside) {
...
}

Ok, if you need some variabes to allow developers can choose draw lables or not, you can do this as your way.
I just custome a little of your code to be able for my problem

This can be done easily with the ValueFormatter

Hi Phil. and how about the text? the value may be gone , but the text still appears in the chart.

I am interested in this solution too. I can hide value with valueformatter, but I can not hide labels. Solution to not add entries in dataSet is not applicable in my case, because in my ChartGestureListener user can change chart and I need all data from previous chart (on click I build new chart and remove old one).
So, in PieChart I dont want to show labels and values where value == 0, but I need to show them in BarChart.

If there is any solution for this, please share.
Thanks!

hi urospodkriznik, I do not remember well, but I think the fix I suggested, contemplating this change you want. Please, try it and then tell us if it worked.
The implementation is in link above.

@PhilJay if the pie chart is divided into 3 sections and if two of them are zero then they get overlapped . Please explain how this can be done using value formatter . I am using latest version of the library

@rajeevjaiswal Did you find an answer to this?

@PhilJay any solution in regarding that. i need hide text label.

Method used to hide draw Slice text
pieChart.setDrawSliceText(false);

@dwivedi this method is deprecated now is there any one?

@son2017 Deprecated -> use setDrawEntryLabels(...) instead.

@thadeubatista
how you remove value for 0 as you show in the picture..plz explain

@dwivedi
pieChart.setDrawSliceText(false);
it doesnt work for me

setDrawEntryLabels(false) would hide all the labels.
What if I'm intending to partially display labels?
For example: I have 3 parties as entries : ["Party A","Party B","Party C"] and I only want to show the first two and hide the third.

All right, legend.setCustom(List<LegendEntry>) would do this trick.
Just give empty string to PieEntiry and then customize legend labels with full labels.

@WangJi
setDrawEntryLabels(false) would hide all the labels.
Perfect solution for me. Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DarkHelmet67 picture DarkHelmet67  路  3Comments

galex picture galex  路  3Comments

manucheri picture manucheri  路  3Comments

tsengvn picture tsengvn  路  3Comments

andreyfel picture andreyfel  路  3Comments