MPAndroidChart
MPAndroidChart copied to clipboard
zoomAndCenterAnimated not centering on x value
I'm trying to use the method zoomAndCenterAnimated on a line graph, but the result I get, no matter the x-value entered, is the graph zooming and centering on the very first data point.
I've tried implementing on the sample project with a simple y = x straight line graph and no matter which x;y value I choose to center on it still zooms in and centers on the first data point.
I got same issue, any work around?
It happens to me as well, on the latest release of the library. Always zooms in at the first data point on the X axis.
I did figure it out but never posted a solution.
In AnimatedZoomJob.getInstance(...) the zoomCenter variables are never set. The parameters are passed but nothing is done to it.
If @PhilJay wants I can fork and push a request, but here's the fixed method so long:
public static AnimatedZoomJob getInstance(ViewPortHandler viewPortHandler, View v, Transformer trans, YAxis axis, float xAxisRange, float scaleX, float scaleY, float xOrigin, float yOrigin, float zoomCenterX, float zoomCenterY, float zoomOriginX, float zoomOriginY, long duration)
{
AnimatedZoomJob result = pool.get();
result.mViewPortHandler = viewPortHandler;
result.xValue = scaleX;
result.yValue = scaleY;
result.mTrans = trans;
result.view = v;
result.xOrigin = xOrigin;
result.yOrigin = yOrigin;
result.yAxis = axis;
result.xAxisRange = xAxisRange;
result.resetAnimator();
result.animator.setDuration(duration);
result.zoomCenterX = zoomCenterX;
result.zoomCenterY = zoomCenterY;
result.zoomOriginX = zoomOriginX;
result.zoomOriginY = zoomOriginY;
return result;
}
Thanks for posting the fix here!
He hasn't merged any pull requests for the past 2 months, but I'm sure he will do so when he finds the time. Plus all of us will appreciate if you do!
I've encountering the same issue, is the fix closed with merge?
Five years later and still the same issue. I created a PR with the fix @a-bresler suggested. Hopefully it gets merged.
Five years later and still the same issue. I created a PR with the fix @a-bresler suggested. Hopefully it gets merged.
While you wait for a merge (the last was 3 years ago), I merged it here already