hellocharts-android
hellocharts-android copied to clipboard
How to add datetime to x axis and others
1, I have the axisXBottom, and I need to write out datetimes there, how can I do that?
2, Also I have axisYLeft with some values 0.0 to 1.0 I want to draw out something like
(0.5 - 35$ ) (0.6 - 42$ ) ...etc
I can use setAppendedText, but how can I get the formatter value back?
I need something like:
setAppendedText(" " + (formatter.value * 7) + "$" )
Set the label value.
for setting Date as x axis value change the date in to string in required format and use them.
Some thing like this.
List<AxisValue> xAxisValues = new ArrayList<>();
for(int i= 0; i< numberOfPoints, i++)
xAxisValues.add(new AxisValue(i, dates[i].toString().toCharArray()));
Axis axisX = new Axis();
axisX.setValues(xAxisValues);
chart.setAxisXBottom(axisX);
I think you can use the same for Y axis also.
i have done those this things as per your answered but still it can't give me output for dynamic data. can you help in this case?
Here is my code sample : LineChartData data = new LineChartData();
List<AxisValue> xAxisValues = new ArrayList<>(); List<AxisValue> yAxisValues = new ArrayList<>(); for (int i = 0; i < 10; i++) {
AxisValue axisValue = new AxisValue(i); axisValue.setValue(i); axisValue.setLabel("A" + i); xAxisValues.add(axisValue);
AxisValue axisValueY = new AxisValue(i); axisValueY.setValue(i); axisValueY.setLabel("Y" + (i+2)); xAxisValues.add(axisValueY); }
Axis axisX = new Axis(); axisX.setName("Test"); axisX.setValues(xAxisValues); data.setAxisXBottom(axisX);
Axis axisY = new Axis(); axisY.setName("User"); axisY.setValues(yAxisValues); data.setAxisYLeft(axisY);
chart.setLineChartData(data);