0
votes

I'm relatively new to io6 programming and struggling with getting core plot to put axis labels where I want them. I think the tick marks are in the right location but with the code below, the labels are missing. I want the tick marks located at evenly spaced intervals over the NSmutableArray xd. But the label values should be the exponentiated value of the tick mark locations. Can anyone offer any advice?

thanks in advance

NSMutableArray *xd = [[dataClass sharedInstance] xGrid];

CPTXYAxis *x = axisSet.xAxis;
x.labelingPolicy=CPTAxisLabelingPolicyNone;

int totalNumberOfPoints = 10.0;
int i = 0;
NSMutableSet *xLabels = [NSMutableSet setWithCapacity:totalNumberOfPoints];
NSMutableSet *xLocations = [NSMutableSet setWithCapacity:totalNumberOfPoints];
while (i < totalNumberOfPoints)
{
    NSNumber *xData = [NSNumber numberWithDouble:[[xd objectAtIndex:(i*100.0/totalNumberOfPoints)] doubleValue]];
    double xData2 = exp([[xd objectAtIndex:(i*100.0/totalNumberOfPoints)] doubleValue]);
    CPTAxisLabel *label = [[CPTAxisLabel alloc] initWithText:[NSString stringWithFormat:@"%.2f", xData2] textStyle:x.labelTextStyle];
    label.tickLocation = CPTDecimalFromInt([xData doubleValue]);
    label.offset = x.majorTickLength;

    if (label)
    {
        [xLabels addObject:label];
        [xLocations addObject:xData];
    }

    i ++;
}

EDIT: I may not have been clear. The problem I'm having is that with the code above there are no labels at all showing up on the graph.

1
Do you want to superscript the exponent or just use a text format like "2.0e5" or "2.0 x 10^5"? - Eric Skroch
The exponentiated values will all be small enough in magnitude that i won't need special formatting. just %.2f. - user2853230

1 Answers

0
votes

You have to add the new labels and tick locations to the axis.

axis.majorTickLocations = xLocations;
axis.axisLabels = xLabels;