Mpandroidchart: Stacked Bar chart - Bar Data label over lapping

Created on 31 Jul 2015  路  2Comments  路  Source: PhilJay/MPAndroidChart

I have a stacked bar chart whose entries are added from a database. The code is something like this:yVals.add(new BarEntry(new float[]{v1, v2, v3}, xIndex)); where v1, v2 and v3 are values got from the database.

My problem some times, the value of v2 or v3 is 0 so when I add the entry to the chart, the bardata label for that field(which is 0) overlaps the previous stack's(v1 or v2) bardata label.

Is there any option to disable the label only for 0 values?

Thanks.

P.S. I have attached an image showing the label being overlapped in the 3rd yellow stack, 6th green stack and 7th green stack.

screenshot_2015-07-31-22-31-48 1

Most helpful comment

Edit: I found a solution for this. Just add a statement in the ValueFormatter saying return an empty string if the value is 0.

For example,
public String getFormattedValue(float value) {
if(value==0)
return "";
else
return mFormat.format(value);
}

All 2 comments

Edit: I found a solution for this. Just add a statement in the ValueFormatter saying return an empty string if the value is 0.

For example,
public String getFormattedValue(float value) {
if(value==0)
return "";
else
return mFormat.format(value);
}

Hi
I need the same requirement to remove 0 values in Stacked bar chart.I used your suggestion but still I could see the 0 values in my chart.
Below is my code snippet

      leftAxis.setValueFormatter(new IAxisValueFormatter() {
        @Override
        public String getFormattedValue(float value, AxisBase axis) {
            String stringVal;
            if (value == 0.0 | value ==0) {
                stringVal = "";
            }
            else {
                stringVal = String.valueOf(value);

            }
            return stringVal;
        }

    });

Do you have any idea?

Regards
Divya

Was this page helpful?
0 / 5 - 0 ratings

Related issues

galex picture galex  路  3Comments

OnlyInAmerica picture OnlyInAmerica  路  3Comments

SutharRohit picture SutharRohit  路  3Comments

DarkHelmet67 picture DarkHelmet67  路  3Comments

andreyfel picture andreyfel  路  3Comments