views:

432

answers:

1

I have a simply bar graph created for my iPhone application however I want to manually add the x-axis labels. Has anyone worked out a way to do this?

I found the CPXYAxisSet.xAxis.axisLabels property however when I create an NSSet and assign it using:

axisSet.xAxis.axisLabelingPolicy = CPAxisLabelingPolicyNone;
NSSet *labels = [[NSSet alloc] initWithObjects:@"year 1", @"year 2" @"year 3", nil];
axisSet.xAxis.axisLabels = labels;

I get a:

*** Terminating app due to uncaught exception 'CALayerInvalid', reason: 'expecting model layer not copy: year 1'

error.

Anyone have a solution?

Many thanks.

+2  A: 

I believe this has been addressed in the Core Plot mailing list. The axisLabels property takes in a set of CPAxisLabel objects (a descendant of CALayer), not NSStrings, which is why you're getting the above exception.

To create a CPAxisLabel for each of your custom labels, use code similar to the following:

CPAxisLabel *newLabel = [[CPAxisLabel alloc] initWithText: customText]; 
newLabel.tickLocation = [tickLocation decimalValue]; 
newLabel.textStyle = x.axisLabelTextStyle; 
newLabel.offset = x.axisLabelOffset + x.majorTickLength; 

EDIT (1/18/2010): An example of this is now present in the Core Plot iPhone test application, under the bar chart tab.

Brad Larson
Many thanks. I'll also take the hint and head over ot the Core Plot mailing list :-)
Zen-C
No problem. I'm just one of the few contributors with an account here, so you'll probably get more eyeballs on an issue there.
Brad Larson