How to setLabelCount flexible depend on granularity

Viewed 97

For example, I have line chart data like

YourData[] dataObjects = new YourData[4];
dataObjects[0] = new YourData(10,10);
dataObjects[1] = new YourData(11,11);
dataObjects[2] = new YourData(12,12);
dataObjects[3] = new YourData(15,15);

Currently, I want to display the granularity 0.5f, so I use but it not working

YAxis leftAxis = chart.getAxisLeft();
leftAxis.setGranularityEnabled(true);
leftAxis.setGranularity(0.5f);

enter image description here

Then I found that, if I setLabelCount with value >= 11, the granularity will work well

leftAxis.setLabelCount(11);

However, my data can change then the fixed value 11 may not work well. I see that the granularity still work well if we can set labelCount value greater than correct labelCount value (example 12,13,...).
And the maximum of labelCount in MPAndroidChart is 25

public void setLabelCount(int count) {
    if (count > 25)
        count = 25;
    if (count < 2)
        count = 2;
    ...
}

Is it good if I always set labelCount = 25 to make granularity work? Or is there any flexible way to make granularity work? Any help or suggestion would be great appreciated.

enter image description here

0 Answers
Related