Mandroid Mandroid - 1 year ago 139
Android Question

Android MPAndroidChart: How to customise bar values

I am using MPAndroidChart in my android app. I use BarChart. So I prepare BarEntry for it. I also enable y value to be displayed on top of the bar. My issue is that I want values on top of the bars to be whole numbers,like 5.But currently it displays as 5.00.

enter image description here

So how to make 5.00 as 5?

Answer Source

Values are formatted using the ValueFormatter interface. Here's a simple formatter that converts all values to integers:

public class IntValueFormatter implements ValueFormatter {

    public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
        return String.valueOf((int) value);

You can then use this formatter for both BarData and individual BarDataSet objects like this:

barData/barDataSet.setValueFormatter(new IntValueFormatter());

For more information on ValueFormatter, check the following links:

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