5
votes

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?

3

3 Answers

11
votes

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

0
votes

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.

0
votes

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)