RunLoop RunLoop - 10 months ago 67
Android Question

Hide 0 values in staked bar chart

I am using MPAndroidChart to show a stacked bar chart containing 2 stacks. However 0 values are shown and overlap normal values as per screenshot. How can I hide 0 values?enter image description here

Answer Source

Use the IValueFormatter interface.


public class MyValueFormatter implements IValueFormatter {

    private DecimalFormat mFormat;

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

    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.