Force BarChart Y axis labels to be integers?

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

    Here is the simple solution which will benefit someone who is looking for the answer.

    1. Y-Axis labels count

      barChart.getAxisLeft().setLabelCount(7, true); //if you want 6 labels then value should be 7

    2. Calculate maxValue

      • Get maxValue from values need to be included in the chart
      int maxValueMod = (maxValue + 2) % 6; //calc mod, here 2 is to display Legend and 6 is no of labels
      maxValue = maxValue + (6-maxValueMod); // calculate final maxValue to set in barchart
      barChart.getAxisLeft().setAxisMaximum(maxValue+2); ```
      

提交回复
热议问题