MPAndroidChart - How to show y values โ€‹โ€‹when your value is zero?

I am using the 2.0.8 release of MPAndroidChart

I have a problem where y values โ€‹โ€‹are zero and bars are not displayed in BarChart.

I checked the sample project:

Immutable code:

enter image description here

A simple change for all y values โ€‹โ€‹is zero on line 260 , s

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

but this happens:

enter image description here

And the same thing happens in my project, when some bars have non-zero values, all bars are displayed, for example:

enter image description here

but when all columns are zero, no row is displayed, and only one label is displayed on the x axis

How to fix it?

I need the chart to show all values, even the 'y' values โ€‹โ€‹are zero.

+5
source share
1 answer

I was getting the same problem as you. I have a histogram, when all y values โ€‹โ€‹are 0, the panel does not appear at all. but if there is at least one y value that is not 0, a bar is displayed, even the rest of the y values โ€‹โ€‹are 0.

so I think this is a bug from MPAndroidChart.

but I found a way to tweak it a bit. you need to set a fixed value for the maximum axis when all y values โ€‹โ€‹are 0.

here is the code to set the value of the fixed maximum axis:

 leftAxis.setAxisMaxValue(100f); 

doing this when all y values โ€‹โ€‹are 0, you set the maximum axis value to 100, but you can set it to another value as long as the maximum axis value is not 0, and the histogram will show even if all y values โ€‹โ€‹are 0.

hope it fixes your problem.

+3
source

Source: https://habr.com/ru/post/1215851/


All Articles