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

点点圈 提交于 2019-12-06 02:06:18

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/29699230/mpandroidchart-hide-0-value-labels-in-a-stacked-bar-chart

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!