Reputation: 3056
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.
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:
How can I achieve this?
Upvotes: 0
Views: 1291
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:
I hope this will help you.
Upvotes: 1
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