Force BarChart Y axis labels to be integers?

后端 未结 8 747
滥情空心
滥情空心 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:21

    To add to the solution, if someone just wants to remove the decimal and repeated values, you can do this :

    IAxisValueFormatter yAxisValueFormatter = new IAxisValueFormatter() {
          @Override
          public String getFormattedValue(float v, AxisBase axisBase) {
    //check for decimal value
            if (v - (int) v != 0) {
              return "";
            } else {
              return String.valueOf((int) v);
            }
          }
        }; 
        leftAxis.setValueFormatter(yAxisValueFormatter);
        rightAxis.setValueFormatter(yAxisValueFormatter);
    

提交回复
热议问题