3

I know label rotation is not supported in ios-charts. Any issue asking for this is promptly closed however this is a very basic feature. I've seen people posts about how to do it in MPAndroidChart (which this is based on) but those solutions appear to be Android specific. Does anyone know of a way to get 45 or 90 degree labels rotations for a bar chart in iOS-charts?

rjb101
  • 514
  • 5
  • 14
  • take a look at http://stackoverflow.com/questions/10289898/drawing-rotated-text-with-nsstring-drawinrect and http://stackoverflow.com/questions/30089756/rotating-nsstring-in-swift – Wingzero Oct 13 '15 at 01:56
  • thanks, while good for rotating text in general, it doesn't really help in this specific framework, which is what I'm trying to do. – rjb101 Oct 13 '15 at 19:11
  • They share the same strategy, why won't it work? All using CG – Wingzero Oct 14 '15 at 01:36
  • the problem is I don't see individual labels exposed via the API, maybe if I start hacking the framework then yes I could use standard methods – rjb101 Oct 18 '15 at 09:14

2 Answers2

8

To rotate a label you need to do the following:

someChartView.xAxis.labelRotationAngle = CGFloat(rotationAngle) // -90.0 or -45.0

Examples:

barChartView.xAxis.labelRotationAngle = -45.0 
lineChartView.xAxis.labelRotationAngle = -90.0
rptwsthi
  • 10,094
  • 10
  • 68
  • 109
DoesData
  • 6,594
  • 3
  • 39
  • 62
4

First - let me emphasize that you are very wrong:

  1. MPAndroidChart existed for a long time without any issue about rotating x-axis labels, so there wasn't a need for anyone.
  2. In ios-Charts there was one issue about it, tagged as a feature request, and pending until yesterday (Oct 11). There was one other opened recently, marked as duplicate issue.

Secondly:
I've implemented this feature in the latest master. Please pull from master until there's a version release.

daniel.gindi
  • 3,457
  • 1
  • 30
  • 36