Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MPAndroidChart: Hide 0 value labels in a stacked bar chart [closed]

I am using MPAndroidChart to show a stacked bar chart containing two sets of data (Income and Expenditure). I'm having an issue when the value is 0 the label overlap other x axis values.

In the case of the screenshot you can see that the bars which have values have overlapping values for the following dates: 14/4, 15/4 and 16/4.

How can I hide the 0 values to stop the overlapping issue?Stacked bar chart graph

like image 776
RunLoop Avatar asked Apr 17 '15 12:04

RunLoop


1 Answers

Use the IValueFormatter interface.

Example:

public class MyValueFormatter implements IValueFormatter {

    private DecimalFormat mFormat;

    public MyValueFormatter() {
        mFormat = new DecimalFormat("###,###,##0.00");
    }

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

        if(value > 0) {
            return mFormat.format(value);
        } else {
            return "";
        }
    }
}

Set it for the chart-data:

barData.setValueFormatter(new MyValueFormatter());

Also check the documentation.

like image 81
Philipp Jahoda Avatar answered Oct 22 '22 13:10

Philipp Jahoda