自定义轴标签不会显示在左侧y轴和右侧y轴上

时间:2014-01-23 00:28:51

标签: core-plot

我有一个自定义标签和刻度位置脚本,适用于我的左y轴。一旦我尝试包含一个正确的y轴,标签将只显示在左侧或右侧。主要和次要的勾选位置显示在两侧。如果我注释掉y2.labels的代码,标签在右边,包括代码行,只在左边?认为有一些我想念的简单,只是找不到它。

Thanx

编辑: 有趣的是当我评论出“y3.labelingPolicy = CPTAxisLabelingPolicyNone;”左手y轴失去自定义字母标签并移动到十进制,右手y轴只是得到数字。

CPTXYAxis *y2 = axisSet2.yAxis;
y2.axisLineStyle = graphLineStyle;
y2.labelingPolicy = CPTAxisLabelingPolicyNone;
NSArray *y2MajorLocation = [NSArray arrayWithObjects:[NSDecimalNumber numberWithInt:0], [NSDecimalNumber numberWithInt:2], [NSDecimalNumber numberWithInt:4],
                                [NSDecimalNumber numberWithInt:6], [NSDecimalNumber numberWithInt:8], [NSDecimalNumber numberWithInt:10], [NSDecimalNumber numberWithInt:12],
                                [NSDecimalNumber numberWithInt:14], [NSDecimalNumber numberWithInt:16], nil];
NSArray *y2MinorLocation = [NSArray arrayWithObjects:[NSDecimalNumber numberWithInt:3], [NSDecimalNumber numberWithInt:5],
                            [NSDecimalNumber numberWithInt:7], [NSDecimalNumber numberWithInt:9], [NSDecimalNumber numberWithInt:11], [NSDecimalNumber numberWithInt:13],
                            [NSDecimalNumber numberWithInt:15], nil];
NSArray *y2Label = [NSArray arrayWithObjects:@"", @"S", @"SW", @"W", @"NW", @"N", @"NE", @"E", @"SE", nil];
CPTMutableTextStyle *y2LabelStyle = [CPTMutableTextStyle textStyle];
y2LabelStyle.color = [[CPTColor whiteColor] colorWithAlphaComponent:1];
y2LabelStyle.fontName = @"Helvetica-Bold";
y2LabelStyle.fontSize = 9.0f;

NSUInteger y2labelLocation = 0;
NSMutableArray *y2customLabels = [NSMutableArray arrayWithCapacity:[y2Label count]];
NSMutableArray *y3customLabels = [NSMutableArray arrayWithCapacity:[y2Label count]];
for (NSNumber *tickLocation in y2MajorLocation) {
    CPTAxisLabel *newLabel = [[CPTAxisLabel alloc] initWithText: [y2Label objectAtIndex:y2labelLocation++] textStyle:y2LabelStyle];
    newLabel.tickLocation = [tickLocation decimalValue];
    newLabel.offset = -4;
    [y2customLabels addObject:newLabel];
    newLabel.offset = 4;
    [y3customLabels addObject:newLabel];
}
y2.axisLabels =  [NSSet setWithArray:y2customLabels];
y2.majorTickLocations = [NSSet setWithArray:y2MajorLocation];
y2.minorTickLocations = [NSSet setWithArray:y2MinorLocation];
y2.majorTickLength = 4;
y2.minorTickLength = 2;
y2.majorTickLineStyle = graphLineStyle;
y2.minorTickLineStyle = graphLineStyle;
y2.axisConstraints = [CPTConstraints constraintWithLowerOffset:0];

CPTXYAxis *y3 = [(CPTXYAxis *)[CPTXYAxis alloc] initWithFrame:CGRectZero];
y3.labelingPolicy = CPTAxisLabelingPolicyNone;
y3.axisLineStyle = graphLineStyle;
y3.coordinate = CPTCoordinateY;
y3.plotSpace = plotSpace2;
y3.axisConstraints = [CPTConstraints constraintWithUpperOffset:0];
y3.labelOffset = 3;
y3.labelTextStyle = y2LabelStyle;
y3.majorTickLength = 4;
y3.minorTickLength = 2;
y3.majorTickLineStyle = graphLineStyle;
y3.minorTickLineStyle = graphLineStyle;
y3.tickDirection = CPTSignPositive;
y3.majorTickLocations = [NSSet setWithArray:y2MajorLocation];
y3.minorTickLocations = [NSSet setWithArray:y2MinorLocation];
y3.axisLabels =  [NSSet setWithArray:y3customLabels];

graph2.axisSet.axes = @[x2, y2, y3];

0 个答案:

没有答案