Hello I'm using version 1.0, this is how I'm setting up my girds:
//Get the axes' axisSet property
CPTXYAxisSet *axisSet=(CPTXYAxisSet *)[graph axisSet];
CPTXYAxis *yAxis=[axisSet yAxis];
CPTXYAxis *xAxis=[axisSet xAxis];
//Avoid overhead, create this objects once
CPTColor *grayColor=[[CPTColor colorWithGenericGray:0.2]
colorWithAlphaComponent:0.75];
CPTLineStyle *gridLineStyle=[PBUtilities lineStyleWithWidth:0.75
andColor:grayColor];
//Y axis gird lines
[yAxis setMajorGridLineStyle:gridLineStyle];
[yAxis setMinorGridLineStyle:gridLineStyle];
[yAxis setTickDirection:CPTSignNone];
//X axis gird lines
[xAxis setMajorGridLineStyle:gridLineStyle];
[xAxis setMinorGridLineStyle:gridLineStyle];
[xAxis setTickDirection:CPTSignNone];
And when I set up my ticks:
int i=0;
NSMutableArray *newAxisLabels=[[NSMutableArray alloc] init];
NSMutableArray *tickLocations=[[NSMutableArray alloc] init];
CPTAxisLabel *newLabel=nil;
//Keep the current appearance by retrieving these properties
CPTXYPlotSpace *plotSpace=(CPTXYPlotSpace *)[graph
defaultPlotSpace];
CPTXYAxisSet *axisSet=(CPTXYAxisSet *)[graph axisSet];
CPTXYAxis *xAxis=[axisSet xAxis];
CPTTextStyle *currentStyle=[xAxis labelTextStyle];
//If you don't set the policy to none, you won't be able to see
your custom labels
[xAxis setLabelingPolicy:CPTAxisLabelingPolicyNone];
//Avoid the over-head of repeating this calculations for each
iteration
float majorTickInterval=CPTDecimalFloatValue([xAxis
majorIntervalLength]);
CGFloat tickLabelOffset=[xAxis labelOffset]+[xAxis
majorTickLength]/2.0;
//The use of the ranges help us calculate how many ticks are
visible in the scrreen
float rangeLocation=CPTDecimalFloatValue([[plotSpace xRange]
location]);
float rangeLength=CPTDecimalFloatValue([[plotSpace xRange]
length]);
int visibleTicks=(int)floor((rangeLength / majorTickInterval));
#ifdef DEBUG
NSLog(@"There are %d visible ticks for the X axis", visibleTicks);
#endif
//Just be careful and let the programmer know if he screwed
something
if ([labels count] < visibleTicks) {
[NSException raise:@"PBPLot" format:@"You provided %d X ticks
labels, the method needs %d", [labels count], visibleTicks];
}
//Go through every of the visible ticks and add the custom label
provided
for(i=0; i<=visibleTicks; i++){
//Add the locations of the ticks, otherwise you will loose all
the lines and grids
[tickLocations addObject:[NSDecimalNumber
numberWithFloat:rangeLocation + (i * majorTickInterval)]];
newLabel=[[CPTAxisLabel alloc] initWithText:[labels
objectAtIndex:i] textStyle:currentStyle];
[newLabel setTickLocation:CPTDecimalFromFloat(rangeLocation +
(i * majorTickInterval))];
[newLabel setOffset:tickLabelOffset];
[newLabel setRotation:rotation];
[newAxisLabels addObject:newLabel];
[newLabel release];
}
//Add the ticks locations, otherwise no girds will be shown
[xAxis setMajorTickLocations:[NSSet setWithArray:tickLocations]];
[tickLocations release];
//Add the labels and manage your memory
[xAxis setAxisLabels:[NSSet setWithArray:newAxisLabels]];
[newAxisLabels release];