I m coding a line chart using MPAndroidChart, my code works without any error but pinch zooming goes to infinity, because of that in some devices CPU has 100%. How can i restrict max pinch zoom?
How to set max pinch zoom in MPAndroidChart
Asked Answered
The mpandroidhchart developer implemented this in this commit: https://github.com/PhilJay/MPAndroidChart/commit/ba152072a6a7adbf8e9e166904798219c1200172
But I'm still waiting for a new release version. Further, you just need to call
chart.getViewPortHandler().setMaximumScaleX(2f);
chart.getViewPortHandler().setMaximumScaleY(2f);
And this will limit the zoom in factor 2
setScaleMinima(2f, 1f)
Setting scale min to 0f same as zoom out too infinity. 1f would allow you to adjust zoom so you can see the whole graph.
Thanks for your answer @AlexBalio but that doesn't fix my problem. I need a method to restrict zoom, for ex user shouldn't zoom after 3x.. but MPAndroidChart doesn't have setMaxZoom(float f,..) unfortunality. Do you have any other advice to fix it? –
Hazelwood
What I found helpful and ended up using was setting the visible range which also stops the zoom to not go beyond the max or min values that you set. For example:
chart.setVisibleYRangeMinimum(1f, YAxis.AxisDependency.LEFT)
chart.setVisibleXRangeMinimum(5f)
© 2022 - 2024 — McMap. All rights reserved.