I am using MPAndroidChart, how I can reset the zoom? For example:
1. User make zoomming in the chart
2. User click one button to reset the zoom (back to the default zoom)
You can reset the zoom by calling chart.fitScreen()
. This will reset the chart viewport to it's original state (fully zoomed out).
I think that the flagged answer is not complete, in case the whole chart is not shown in the viewport (e.g. max 5 samples in viewport over the total of 20 dataset samples). Checking deeply the documentation I've found a working solution for me:
zoom(float scaleX, float scaleY, float x, float y)
: Zooms in or out
by the given scale factor. x and y are the coordinates (in pixels) of
the zoom center. Remember that a scale of 1f = no zoom.zoom(float scaleX, float scaleY, float xValue, float yValue, AxisDependency axis)
: Zooms in or out by the given scale factor.
xValue and yValue are the actual data values (not pixels) of the zoom
center. Remember that a scale of 1f = no zoom.zoomAndCenterAnimated(float scaleX, float scaleY, float xValue, float yValue, AxisDependency axis, long duration)
: Zooms by the specified scale factor and centers the viewport to the specified values on the specified axis in an animated way (v2.2.3 or above).Calling one of the methods above will provide the trick (e.g. zoomAndCenterAnimated(1f, 1f, 0, 0, AxisDependency.LEFT, 500L)
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With