Ashish P
Ashish P

Reputation: 3056

Show Text on left Axis in iOS Chart

I want to show line chart on my dashboard screen and everything working fine using following library: https://github.com/danielgindi/Charts

I'm using same code as following: Display three label on XAxis of chart.

Just I want to display following text on left axis of chart as following image.

Show text on left axis

I have also tried following solution, but it's make more space around label and my graph not display proper.

self.lblLeftAxisLabel.transform = CGAffineTransform(rotationAngle: -CGFloat.pi / 2)

Output for above code:

Transform label, make more space around it

How can I achieve this?

Upvotes: 0

Views: 1291

Answers (2)

Sagar Chauhan
Sagar Chauhan

Reputation: 5823

If you are using storyboard to place label, than take outlets of leading and trailing constrains.

Update your constraints before rotating label which will move your label and view toward left direction. This will move label outside of screen before rotating.

Code:

self.yourLabelLeadingConstrint.constant = -(self.lblLeftAxisLabel.frame.size.width / 2) + self.lblLeftAxisLabel.frame.size.height

self.yourLabelTrailingConstrint.constant = -(self.lblLeftAxisLabel.frame.size.width / 2) + self.lblLeftAxisLabel.frame.size.height

self.view.layoutIfNeeded()

Then add code to rotate label as you have already doing.

self.lblText.transform = CGAffineTransform(rotationAngle: -CGFloat.pi / 2)

See following screenshot:

Label Rotate

I hope this will help you.

Upvotes: 1

batphonghan
batphonghan

Reputation: 485

This may not what's you expected but could I suggest programmatic add a UILabel beside that chart and rotated it:

yourLabel.transform = CGAffineTransform(rotationAngle: -CGFloat.pi / 2)

Upvotes: 1

Related Questions