MPAndroidChart: how to set up bar value labels

I am using MPAndroidChart in my android application. I use BarChartconsisting of BarEntry. I also included y values ​​that will be displayed on top of the line.

My problem is that I want the values ​​at the top of the columns to be integers, for example 5. But currently the values ​​are displayed as 5.00.

the top of one line from a histogram with a value label above it, displaying

So how do I do 5.00how 5?

+4
source share
1 answer

Values ​​are formatted using an interface IValueFormatter. Here's a simple formatting element that converts all values ​​to integers:

public class IntValueFormatter implements IValueFormatter {

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

BarData BarDataSet, :

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

IValueFormatter, :

+4

Source: https://habr.com/ru/post/1651093/


All Articles