【发布时间】:2012-02-23 15:41:07
【问题描述】:
我正在使用 Core Plot 库在 iOS 上绘制图表。我想在 yAxis 的网格线之间添加颜色。我设法通过设置轴的alternatingBandFills 属性来做到这一点。但是,我还必须在 yAxis 上使用自定义标签,并且当我提供自定义标签时,alternatingBandFills 属性由于某种原因不起作用。
任何帮助如何添加颜色到 yAxis 上网格线之间的空间以及使用自定义标签将不胜感激。
我现在使用的代码如下:
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];
【问题讨论】:
标签: ios objective-c colors core-plot