Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MPAndroidChart - How to show the y-values when your value is zero?

I using the 2.0.8 release of MPAndroidChart

I have a problem when the y-values are all zero, and the bars are not shown in the BarChart.

I checked the sample project:

Unchanged code:

enter image description here

Just changing for all values of y are zero in the line 260, with

yVals1.add(new BarEntry(0, i));

but this happens:

enter image description here

And the same happens in my project, when some bars have nonzero values, all bars are displayed, like this:

enter image description here

but when all the bars are zero, no bars are shown and only one label is shown on the x-axis

How to fix this?

I need the chart display all values even the values of 'y' are all zero.

like image 970
mlozdev Avatar asked Mar 22 '15 06:03

mlozdev


1 Answers

i was getting the same kind of problem as you. i have a bar chart, when all the y values are 0, the bar won't show at all. but if there is at least one y value that isn't 0, the bar will showed up even the rest of the y values is 0.

so i think this is a bug from MPAndroidChart.

but i found a way to tweak it a little bit. you need to set the fixed max axis value, when all the y values are 0.

here is the code to set the fixed max axis value :

leftAxis.setAxisMaxValue(100f);

by doing that, when all the y values are 0, you will set max axis value to 100, but you can set it to other value as long as the max axis value is not 0, and the bar chart will shown even if all the y values are 0.

hope it will fix your problem

like image 99
random_dude Avatar answered Oct 29 '22 15:10

random_dude