I use the Core Plot library to draw graphs on iOS. I want to add colors between yAxis grid lines. I managed to do this by setting the alternatingBandFills property of the axis. However, I have to use custom shortcuts on yAxis, and when I provide custom shortcuts, the alternatingBandFills property does not work for some reason.
Any help on adding colors to the spaces between the grid lines on yAxis, as well as using custom shortcuts, would be greatly appreciated.
The code I'm using now looks like this:
CPTXYAxisSet *axisSet = (CPTXYAxisSet *)self.hostedGraph.axisSet; CPTXYAxis *yAxis = axisSet.yAxis; yAxis.orthogonalCoordinateDecimal = CPTDecimalFromDouble(minValueX); yAxis.labelingPolicy = CPTAxisLabelingPolicyNone; NSArray *yAxisTickLocations = [NSArray arrayWithObjects: [NSDecimalNumber numberWithDouble:lowerRedRangeFrom], [NSDecimalNumber numberWithDouble:lowerOrangeRangeFrom], [NSDecimalNumber numberWithDouble:greenRangeFrom], [NSDecimalNumber numberWithDouble:upperOrangeRangeFrom], [NSDecimalNumber numberWithDouble:upperRedRangeFrom], [NSDecimalNumber numberWithDouble:upperRedRangeTo], nil]; NSArray *yAxisLabels = [NSArray arrayWithObjects:@"Label1",@"Label2", @"Label3",@"Label4",@"Label5",@"Label6", nil]; NSUInteger labelLocationY = 0; NSMutableArray *customLabelsY = [NSMutableArray arrayWithCapacity:[yAxisLabels count]]; for (NSNumber *tickLocation in yAxisTickLocations) { CPTAxisLabel *newLabel = [[CPTAxisLabel alloc] initWithText: [yAxisLabels objectAtIndex:labelLocationY++] textStyle:axisSet.xAxis.labelTextStyle]; newLabel.tickLocation = [tickLocation decimalValue]; newLabel.offset = axisSet.xAxis.labelOffset + axisSet.xAxis.majorTickLength; newLabel.rotation = M_PI/4; [customLabelsY addObject:newLabel]; } axisSet.yAxis.axisLabels = [NSSet setWithArray:customLabelsY]; yAxis.alternatingBandFills = [NSArray arrayWithObjects: [CPTColor redColor], [CPTColor orangeColor], [CPTColor greenColor], [CPTColor orangeColor], [CPTColor redColor], nil];
Petar source share