10

i have a Line Chart view in my iOS app.

@IBOutlet weak var lineChartView: LineChartView!

the zooming and touching is enabled. I do not let the user do anything in the chart, even selecting is not allowed.

I tried:

self.lineChartView.pinchZoomEnabled = false
self.lineChartView.dragEnabled = false
self.lineChartView.dragDecelerationEnabled = false

but without any luck. I can still touch the graph and see the cross. I even can pinch to zoom the graph.

How can i turn this behaviour off?+

Joshua
  • 3,055
  • 3
  • 22
  • 37
Peter Shaw
  • 1,867
  • 1
  • 19
  • 32

5 Answers5

21

Doh! in storyboard I can disable "User Interaction Enabled".

that do the trick.

Peter Shaw
  • 1,867
  • 1
  • 19
  • 32
8

The accepted solution didn't work for my barChartView for some reason.

Instead, setting barChartView.isUserInteractionEnabled = false did the trick.

So, for the OP, the following should work self.lineChartView.isUserInteractionEnabled = false

evasilis2000
  • 654
  • 7
  • 5
8

In case anyone would like it to still drag but only disable zooming, you can try self.lineChart.setScaleEnabled(false)

Kelvin Tan
  • 327
  • 3
  • 15
  • `self.setScaleEnabled(false)` worked for me! I could complete my need using the method with `self.pinchZoomEnabled = false` without using UIView method: `isUserInteractionEnabled = false` which prevents all user interaction under the children views – Hiro Jun 11 '20 at 00:48
2

If you want to still have the interactive chart Try these:

chartView.dragXEnabled = false
chartView.dragYEnabled = false
chartView.scaleXEnabled = false
chartView.scaleYEnabled = false
Amir.n3t
  • 2,859
  • 3
  • 21
  • 28
0

I just used

dataSet.highlightColor = .clear
Christopher
  • 73
  • 10