I am trying to set data from string arraylist to xaxis but it gives duplicate data and if i add xAxis.setGranularity(1f); it gives java.lang.ArrayIndexOutOfBoundsException: length=12; index=-1
graphxaxis = new ArrayList<String>();
graphyaxis = new ArrayList<Entry>();
fromyaxis = new ArrayList<Entry>();
toyaxis = new ArrayList<Entry>();
mChart = (LineChart) findViewById(R.id.chart1);
mChart.setOnChartGestureListener(this);
mChart.setOnChartValueSelectedListener(this);
mChart.setDrawGridBackground(true);
// no description text
mChart.getDescription().setEnabled(false);
// enable touch gestures
mChart.setTouchEnabled(false);
// enable scaling and dragging
mChart.setDragEnabled(true);
mChart.setScaleEnabled(true);
mChart.setPinchZoom(false);
MyMarkerView mv = new MyMarkerView(this, R.layout.custom_marker_view);
mv.setChartView(mChart); // For bounds control
mChart.setMarker(mv); // Set the marker to the chart
XAxis xAxis = mChart.getXAxis();
xAxis.setGranularity(1f);
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
xAxis.setValueFormatter(new IAxisValueFormatter() {
@Override
public String getFormattedValue(float value, AxisBase axis) {
return graphxaxis.get((int)value);
}
});
xAxis.setDrawGridLines(false);
YAxis leftAxis = mChart.getAxisLeft();
leftAxis.setAxisMinimum(0f);
leftAxis.setDrawZeroLine(false);
leftAxis.setDrawGridLines(false);
mChart.animateX(2500);
mChart.invalidate();
Legend l = mChart.getLegend();
// modify the legend ...
l.setForm(Legend.LegendForm.LINE);
// // dont forget to refresh the drawing
mChart.invalidate();
Below is the way i am populating the array list
graphxaxis.add(jsonobject.getString("date").substring(0,6));
graphyaxis.add(new Entry(Float.valueOf(i),Float.parseFloat(jsonobject.getString("actual"))));
fromyaxis.add(new Entry(Float.valueOf(i),Float.parseFloat(jsonobject.getString("from"))));
toyaxis.add(new Entry(Float.valueOf(i),Float.parseFloat(jsonobject.getString("to"))));
mChart.notifyDataSetChanged();