Force BarChart Y axis labels to be integers?

后端 未结 8 754
滥情空心
滥情空心 2021-02-05 11:47

I\'ve created a BarChart using MPAndroidChart and I\'m entering the data dynamically. This means that I need my Y axis to also be determined dynamically. All of my data is repre

8条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-05 12:29

    My Solution:

    mChart.getAxisLeft().setValueFormatter(new ValueFormatter() {
        @Override
        public String getFormattedValue(float value) {
            return String.valueOf((int) Math.floor(value));
        }
    });
    
    int max = (int) mChart.getData().getYMax(); 
    mChart.getAxisLeft().setLabelCount(max);
    

提交回复
热议问题