I have a line graph, which shows 2 lines. The data comes from Sqlite where I have the 2 columns that feed the lines, apart from the id, another 2 more one with dates in String and the other with dates in long. In the image the x-axis shows the values of the id but I would like to show the dates in this format as indicated by the green arrow.
If I try to show the date column in String it gives me an exception. If I show it as long does not show anything. Is there a method to show the dates?
LineChart lineChart = (LineChart) view.findViewById(R.id.chart);
int count = cursor.getCount();
int[] fechas = new int[count];
int[] y_sisto = new int[count];
int[] y_diasto = new int[count];
if (cursor.moveToFirst()) {
for (int i = 0; i < count; i++) {
fechas[i] = cursor.getInt(6); //0 = id, 4 = fecha string, 6 = fecha long
y_sisto[i] = cursor.getInt(1);
y_diasto[i] = cursor.getInt(2);
cursor.moveToNext();
}
ArrayList<Entry> values = new ArrayList<Entry>();
for (int i = 0; i < count; i++) {
values.add(new Entry(fechas[i], y_sisto[i]));
}
LineDataSet set1 = new LineDataSet(values, "Sistolica");
set1.setAxisDependency(YAxis.AxisDependency.LEFT);
set1.setColor(Color.RED);
set1.setLineWidth(8);
set1.setDrawHighlightIndicators(true);
set1.setDrawFilled(true);
set1.setFillColor(Color.RED);
set1.setCubicIntensity(1.0f);
set1.setValueTextSize(13f);
ArrayList<ILineDataSet> dataSets = new ArrayList<ILineDataSet>();
dataSets.add(set1);
ArrayList<Entry> values2 = new ArrayList<Entry>();
for (int i = 0; i < count; i++) {
values2.add(new Entry(fechas[i], y_diasto[i]));
}
LineDataSet set2 = new LineDataSet(values2, "Diastolica"); //values2
set2.setAxisDependency(YAxis.AxisDependency.LEFT);
set2.setDrawFilled(true);
set2.setColor(Color.BLUE);
set2.setLineWidth(8);
set2.setCubicIntensity(1.0f);
set2.setValueTextSize(13f);
set2.setValueTextColor(Color.BLUE);
ArrayList<ILineDataSet> dataSets2 = new ArrayList<ILineDataSet>();
dataSets2.add(set2);
LineData lineData = new LineData();
lineData.addDataSet(set1);
lineData.addDataSet(set2);
XAxis xAxis = lineChart.getXAxis();
lineChart.setExtraBottomOffset(20);
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
xAxis.setTextSize(12f);
//xAxis.setTextColor(Color.BLUE);
xAxis.setAxisMaximum(10f);
xAxis.setAxisMinimum(0f);
lineChart.setData(lineData);
lineChart.setScaleEnabled(true);
lineChart.setDrawGridBackground(false);
lineChart.setHighlightPerDragEnabled(true);
lineChart.setDragEnabled(true);
lineChart.invalidate();
}