Every change of the value parameter and displaying it will lead to misleading labels.
For this reason you need to setAxisMinimum(), setAxisMaximum(), setGranularity() and setLabelCount() as appropriate, then display only the labels you want to.
For instance, if you want to display seconds, you can set these parameters like that:
YAxis yAxis = chartName.getAxisLeft();
yAxis.setAxisMinimum(0);//start from 0am
yAxis.setAxisMaximum(86400);//seconds of day
yAxis.setGranularityEnabled(true);
yAxis.setGranularity(1);//values interval
yAxis.setLabelCount(25, true);//from 0 to 24
This will set the value parameter in ValueFormatter to 25 parts which will be equal so when you divide by 3600 to get hour it will be even number.
chartNmae.setValueFormatter(new ValueFormatter() {
@Override
public String getFormattedValue(float value) {
Log.i("Y axis: ", value / 3600 + "h");
int hour = (int)value / 3600;
//if you only want to show some of the values/labels then filter them
return hour % 2 == 0 ? hour + ":00" : "";//return even hour or make the label empty
}
Logcat:
Y axis:: 0.0h
Y axis:: 1.0h
Y axis:: 2.0h
Y axis:: 3.0h
Y axis:: 4.0h
Y axis:: 5.0h
Y axis:: 6.0h
Y axis:: 7.0h
Y axis:: 8.0h
Y axis:: 9.0h
Y axis:: 10.0h
Y axis:: 11.0h
Y axis:: 12.0h
Y axis:: 13.0h
Y axis:: 14.0h
Y axis:: 15.0h
Y axis:: 16.0h
Y axis:: 17.0h
Y axis:: 18.0h
Y axis:: 19.0h
Y axis:: 20.0h
Y axis:: 21.0h
Y axis:: 22.0h
Y axis:: 23.0h
Y axis:: 24.0h
Your values/entries in the chart are the same and might be float but the labels will be integers and will be set at the correct position. So if the entry in the dataset is 36600 (10:10am) it should appear exaclty 1/6th above 10:00am.
But if we change even slightly the axis maximum to setAxisMaximum(86000) then the ValueFormatter will pass parameters with fraction after the decimal point. We can still get even lebels by rounding the ValueFormatter parameter (value) down and return it as label but the value associated with it will appear slightly bellow and now 10:10am (36600 dataset entry) will appear next to 10:00 label (not 1/6th above it) as we rounded down the label actual value but present it on its reserved place on the axis. It is like setting your watch 10 min behind and looking at it. It might show 10:00am but it is actually 10:10am.
Logcat:
Y axis:: 0.0h
Y axis:: 0.9953703h
Y axis:: 1.9907407h
Y axis:: 2.9861112h
Y axis:: 3.9814813h
Y axis:: 4.9768515h
Y axis:: 5.9722223h
Y axis:: 6.9675927h
Y axis:: 7.962963h
Y axis:: 8.958334h
Y axis:: 9.953705h
Y axis:: 10.949075h
Y axis:: 11.944445h
Y axis:: 12.939815h
Y axis:: 13.9351845h
Y axis:: 14.930554h
Y axis:: 15.925924h
Y axis:: 16.921295h
Y axis:: 17.916664h
Y axis:: 18.912035h
Y axis:: 19.907406h
Y axis:: 20.902779h
Y axis:: 21.89815h
Y axis:: 22.89352h
Y axis:: 23.888891h
And if we change the maximum to setAxisMaximum (60000) things are getting really messy:
Logcat:
Y axis:: 0.0h
Y axis:: 0.6944444h
Y axis:: 1.3888888h
Y axis:: 2.0833333h
Y axis:: 2.7777777h
Y axis:: 3.4722223h
Y axis:: 4.1666665h
Y axis:: 4.861111h
Y axis:: 5.5555553h
Y axis:: 6.25h
Y axis:: 6.9444447h
Y axis:: 7.638889h
Y axis:: 8.333333h
Y axis:: 9.027778h
Y axis:: 9.722222h
Y axis:: 10.416667h
Y axis:: 11.111111h
Y axis:: 11.805555h
Y axis:: 12.5h
Y axis:: 13.194445h
Y axis:: 13.888889h
Y axis:: 14.583333h
Y axis:: 15.277778h
Y axis:: 15.972222h
Y axis:: 16.666666h