I'm having a hard time figuring out how to set specific values to the X-AXIS.
For Example, I would like the X-axis to display DAY 0, DAY 1, …,DAY N. But clearly I am not understanding setValueFormatter, I read your documentation and I'm still having trouble understanding.
I tried doing this:
//Fill array
for (int i = 0; i < xAXisNumDay.length; i++) {
xAXisNumDay[i] = "DAY " + i + 1;
}//for
xAxis.setValueFormatter(new IAxisValueFormatter() {
@Override
public String getFormattedValue(float value, AxisBase axis) {
return xAXisNumDay[(int) value % xAXisNumDay.length];
}//formattedValue
});
But it gives me this:
DAY 01, DAY 11, DAY 21, …, DAY 111 --- This is where I get confused!????
Then I realized that it's appending my (i+1) to another kind of increment??? So I tried doing this kind of for loop:
for (int i = 0; i < xAXisNumDay.length; i++) {
xAXisNumDay[i] = "DAY ";
}//for
But that just gives me DAY, DAY, ..., DAY --- Which makes sense! lolol
I exhausted google searches and I need help!
P.S. what if I wanted to use a spinner and have the X-AXIS change according to user input. I.E. spinner entries : days/weeks/months/years and according to user input the axis will display the data by days or weeks or months or years... I got something working but again the X-AXIS values are not displaying as they should (same as above and bear in mind that my array size changes depending on spinner entry chosen)
Please advise and thank you in advance! Much appreciated!
These lines:
for (int i = 0; i < xAXisNumDay.length; i++) {
xAXisNumDay[i] = "DAY " + i + 1;
}
You did con-cat DAY, i and 1 into one string, so the first value will be DAY 01.
Quick fix:
for (int i = 0; i < xAXisNumDay.length; i++) {
xAXisNumDay[i] = "DAY " + (i + 1);
}