Force BarChart Y axis labels to be integers?

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

    Pretty simple. All you need is two things:

    1. Axis value formatter

      mChart.getAxisLeft().setValueFormatter(new ValueFormatter() {
          @Override
          public String getFormattedValue(float value) {
              return String.valueOf((int) Math.floor(value));
          }
      });
      
    2. Axis label count

      int max = findMaxYValue(yourdata); // figure out the max value in your dataset
      mChart.getAxisLeft().setLabelCount(max);
      

提交回复
热议问题