How to set max pinch zoom in MPAndroidChart
Asked Answered
H

3

5

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?

Hazelwood answered 27/7, 2015 at 8:5 Comment(0)
L
11

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

Lelea answered 18/9, 2015 at 10:33 Comment(0)
D
0

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.

Debatable answered 11/8, 2015 at 0:35 Comment(1)
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
D
0

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)
Dugald answered 22/7, 2022 at 20:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.