Mpandroidchart: zoomAndCenterAnimated not centering on x value

Created on 5 Dec 2018  路  4Comments  路  Source: PhilJay/MPAndroidChart

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.

Most helpful comment

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;
    }

All 4 comments

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!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AndroidJiang picture AndroidJiang  路  3Comments

chathudan picture chathudan  路  3Comments

manucheri picture manucheri  路  3Comments

Nima9Faraji picture Nima9Faraji  路  3Comments

andreyfel picture andreyfel  路  3Comments