How can I put a Date in the axis x in LineChart with MPAndroidChart? Now I'm convert the Date (in milliseconds) to string, but when i try to put is in the chart the x values don't display.
LineDataSet dataSet = new LineDataSet(entries, getString(R.string.NDVI_trend));
LineData lineData = new LineData(dataSet);
chart.setData(lineData);
Description description = new Description();
description.setText("");
chart.setDescription(description);
chart.getAxisRight().setEnabled(false);
chart.getXAxis().setPosition(XAxis.XAxisPosition.BOTTOM);
chart.getXAxis().setDrawGridLines(false);
chart.getLegend().setEnabled(false);
String[] dateString = new String[entries.size() +1];
for (int i = 0; i < entries.size(); i++){
dateString[i] = getDate((long)entries.get(i).getX(),"dd MMM yyyy");
}
IAxisValueFormatter axisValueFormatter = new IndexAxisValueFormatter(dateString);
chart.getXAxis().setValueFormatter(axisValueFormatter);
chart.invalidate();
The getData method:
public static String getDate(long milliSeconds, String dateFormat)
{
SimpleDateFormat formatter = new SimpleDateFormat(dateFormat);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(milliSeconds);
return formatter.format(calendar.getTime());
}