RunLoop RunLoop - 1 year ago 102
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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download