8

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

Mark O'Sullivan
  • 10,138
  • 6
  • 39
  • 60
RunLoop
  • 20,288
  • 21
  • 96
  • 151

1 Answers1

17

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.

Mark O'Sullivan
  • 10,138
  • 6
  • 39
  • 60
Philipp Jahoda
  • 50,880
  • 24
  • 180
  • 187