3

Hi i am new to iOS charts.

iOS-Charts

I am using double tap to zoom into my LineChart, but cannot find a way to zoom back out.

Is there a simple way to do this or do I have to intercept the double tap and save my state and restore it later?

I am using Charts 3.0.1 and Swift 3.0.2.

Thanks.

Hasya
  • 9,792
  • 4
  • 31
  • 46
M. Kim
  • 41
  • 6
  • is this problem is still there ? if yes let me know you want it back as normal state means on 0 scale or something else ? – CodeChanger Mar 23 '17 at 12:56
  • Yes it is still a problem. What I meant was that I'd like to be able to doubletap to zoom in (which it does), then have a way (single or another double tao) to zoom back out to the scale it was before my zoom in. Right now if I doubletap a second time, it zooms in even further. – M. Kim Mar 24 '17 at 19:19
  • so for that you have to add one button on screen which will undo ur zoom for that you have to call xAxis & yAxis reset. – CodeChanger Mar 27 '17 at 12:39
  • How do we reset the xAxis & yAxis? In swift 3 or 4 – Nevin Jethmalani Sep 19 '17 at 21:57

2 Answers2

5

This is how you zoom out in Charts

chartView.fitScreen()

Since iOS Charts is analogy to MPAndroidChart, huge part of its documentation, wiki and Q&A applies to both libraries.

DeepBlue
  • 591
  • 9
  • 18
2

This is how we did it. We put this line of code when a button was tapped to reset the zoom.

self.lineChartView.zoomToCenter(scaleX: 0, scaleY: 0)

If you want, you can also put in a plus and minus button and zoom in/out accordingly. You can get the current scale by using this line of code self.lineChartView.scaleX or self.lineChartView.scaleY and then add/subtract a fixed amount every time the zoom in/out button is tapped.

Nevin Jethmalani
  • 2,726
  • 4
  • 23
  • 58