Nick Jones
Nick Jones

Reputation: 523

Core Plot: Y axis label alignment with bars

I'm trying to do something similar to (B) in the diagram below i.e. move the y axis labels so that they are above the relevant bars and left aligned. I have the left hand part of the diagram working (A) (based on bits of this tutorial http://www.gilthonwe.com/2012/06/09/stacked-bar-chart-coreplot-ios/). From my limited core plot experience I can see 3 options.

i) Move all y axis labels relative to their current position such that their bottom left corner becomes the top left corner of the bars. I've failed to find any such methods.

ii) Change the y axis so that the bars extend to either side. Change my tick locations so they are between the existing bars. This seems possible, but fiddly to get the numbers right (especially as in the diagram I am just using numbers, but in practise the labels could have any number of characters and extend any distance to the left).

iii) Create CPTTextLayers for each label, and remove the y axis labelling entirely. This seems the simplest/cleanest solution, but I've been unable to work out how to anchor the bottom left of any text layers to the top left corner of the bar.

or I guess (iv) this just isn't possible in core plot.

Any ideas greatly appreciated.

Changing y axis label positions

Upvotes: 1

Views: 826

Answers (1)

Eric Skroch
Eric Skroch

Reputation: 27381

There are at least two different ways to do this:

  1. Move the labels to the other side of the axis using tickLabelDirection and adjust the bar positions using the barOffset or by modifying the bar locations in the datasource to leave room for the labels.

  2. Create annotations for custom labels (similar to your item iii.). Figuring out the coordinates of the edge of the bar depends on several factors, including the barWidth, barOffset, and barWidthsAreInViewCoordinates.

Upvotes: 2

Related Questions