How to lock the xIndex after add new data?
for example,
list size = 20; element is info by year, 1998 - 2017; when user drag chart to the left( when the first element is 1998), request the before years from server: 1978 - 1997; then add the new date to the list, the list is 1978 - 2017 now; add the data to chart; the first element is not 1998 after setData(), but i want lock the xIndex when add new Data, i tried a lot, but it seems hard on your code, may you resolve it?
Any idea?
I think you're looking for this https://github.com/PhilJay/MPAndroidChart/blob/c1f6fcebf0c3516e067b34312b283189f909bde5/MPChartExample/src/com/xxmassdeveloper/mpchartexample/DynamicalAddingActivity.java
Finally , I get a smooth scroll effect with following code :
YAxis.AxisDependency axisDependency = root.getAxisLeft().isEnabled() ? YAxis.AxisDependency.LEFT : YAxis.AxisDependency.RIGHT;
RectF contentRect = root.getViewPortHandler().getContentRect();
MPPointD center = root.getValuesByTouchPoint(contentRect.centerX(), contentRect.centerY(), axisDependency);
double originalVisibleXRange = root.getVisibleXRange();
double originVisibleYRange = getVisibleYRange(root, axisDependency);
root.setData((newData);
double newVisibleXRange = root.getVisibleXRange();
double newVisibleYRange = getVisibleYRange(root, axisDependency);
double newScaleX = (newVisibleXRange / originalVisibleXRange);
double newScaleY = (newVisibleYRange / originVisibleYRange);
root.zoom((float) newScaleX, (float) newScaleY, (float) center.x, (float) center.y, axisDependency);
root.postInvalidate();
Closing old issue. If anyone still has this question please open a new one.