Question

Why labelingPolicy distinct of CPTAxisLabelingPolicyNone don´t found in string labels???

x.labelingPolicy = CPTAxisLabelingPolicyNone;

enter image description here

I want this GRIDLineStyle, but with my text labels:

x.labelingPolicy = CPTAxisLabelingPolicyFixedInterval

enter image description here

I complete xAxisLabels with this code:

NSMutableArray *labels = [[NSMutableArray alloc] initWithCapacity:[labelsAxisX count]];
    int idx = 0;
    for (NSString *product in labelsAxisX)
    {
        CPTAxisLabel *label = [[CPTAxisLabel alloc] initWithText:product textStyle:x.labelTextStyle];
        label.tickLocation = CPTDecimalFromInt(idx);
        label.offset = 5.0f;
        [labels addObject:label];
        [label release];
        idx++;
    }

    x.axisLabels = [NSSet setWithArray:labels];
    [labels release];
Was it helpful?

Solution

With the CPTAxisLabelingPolicyNone labeling policy, you need to provide the tick locations (major and/or minor) in addition to making the labels. If you'd rather use the fixed interval labeling policy, you could make a custom number formatter for the axis that returns your text labels instead of numbers.

Here's an example adapted from the Labeling Policy Demo in the Plot Gallery example app:

NSMutableSet *tickLocations = [NSMutableSet set];
for ( NSUInteger loc = 0; loc < labelsAxisX.count; loc++ ) {
    [tickLocations addObject:[NSDecimalNumber numberWithUnsignedInteger:loc]];
}
axis.majorTickLocations = tickLocations;

Minor tick locations work the same way.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top