Clifton Labrum
Clifton Labrum

Reputation: 14060

Remove Border and Margin around iOS Charts in Swift

I am using iOS Charts with Swift 3, and I can't figure out how to do a couple things:

  1. I want to remove the margin around the chart. I know the chart goes edge-to-edge in my UI because if I change the chart's background color, it goes all the way to the edge. How do I remove the gap indicated by the red arrows below?

  2. How do I remove the border around the whole graph (note the black arrow)? I already have totalsGraph.drawBordersEnabled = false and it doesn't work. Is there a different option for that?

enter image description here

Thank you!

Upvotes: 16

Views: 9403

Answers (3)

Roy K
Roy K

Reputation: 3319

Actually the way to do it is like this:

chartView.xAxis.enabled = false
chartView.leftAxis.enabled = false
chartView.rightAxis.enabled = false
chartView.drawBordersEnabled = false
chartView.minOffset = 0

Upvotes: 1

Y.Bi
Y.Bi

Reputation: 667

It is minOffset.

/** Sets the minimum offset (padding) around the chart, defaults to 10 */

You can change it as this:

chartView.minOffset = 0

Upvotes: 38

Yalcin Ozdemir
Yalcin Ozdemir

Reputation: 524

that line is actually axis line.

To hide the all the lines, you can use

    totalsGraph.rightAxis.enabled = false
    totalsGraph.legend.enabled = false
    totalsGraph.leftAxis.enabled = false
    totalsGraph.xAxis.labelPosition = .bottom
    totalsGraph.xAxis.drawGridLinesEnabled = false
    totalsGraph.xAxis.drawAxisLineEnabled = false

I am looking for solution to remove margins as well. I will update my answer when I find it.

Upvotes: 9

Related Questions