Here is some sample code taken from a recent project. My x-axis data was an array of NSDates. I set up my axisSet as normal, and then added the following code below:
axisSet.xAxis.labelingPolicy = CPTAxisLabelingPolicyNone;
NSMutableArray *countingXPoints=[[NSMutableArray alloc] init];
NSMutableArray *datesAsStrings=[[NSMutableArray alloc] init];
NSDateFormatter *df=[[NSDateFormatter alloc] init];
[df setDateFormat:@"MM-yy"];
for(int i=0; i<[self.xAxisData count]; i++)
{
[countingXPoints addObject:[NSNumber numberWithInt:i]];
[datesAsStrings addObject:[df stringFromDate:[self.xAxisData objectAtIndex:i]]];
}
NSArray *xCustomTickLocations = [NSArray arrayWithArray:(NSArray *)countingXPoints];
NSArray *xAxisLabels = [NSArray arrayWithArray:(NSArray *) datesAsStrings];
NSUInteger xLabelLocation = 0;
NSMutableArray *xCustomLabels = [[NSMutableArray alloc] initWithCapacity:[xAxisLabels count]];
for (NSNumber *xTickLocation in xCustomTickLocations)
{
CPTAxisLabel *newXLabel = [[CPTAxisLabel alloc] initWithText: [xAxisLabels objectAtIndex:xLabelLocation++] textStyle:axisSet.xAxis.labelTextStyle];
newXLabel.tickLocation = [xTickLocation decimalValue];
newXLabel.offset = 0.0f;
newXLabel.rotation = M_PI/4.0;
[xCustomLabels addObject:newXLabel];
}
axisSet.xAxis.axisLabels=[NSSet setWithArray:xCustomLabels];
For the y-axis part of your question, you can adjust the tick intervals (attributes of CPTXYAxis). To achieve the correct axis height/length, take a look at the xRange, yRange, globalXRange, and globalYRance attributes of your plotspace.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…