我正在使用自定义标签,当 x 轴标签施加在另一个 x 轴标签上时我遇到了问题,当用户缩小散点图(实时)时,我不知道如何隐藏这些标签。
请参阅下面的打印屏幕:我想隐藏“2012 年 8 月”标签。
我怎样才能做到这一点?
下面是我正在使用的代码:
CPTXYAxis *x = axisSet.xAxis;
x.orthogonalCoordinateDecimal = CPTDecimalFromInteger(0);
x.majorIntervalLength = CPTDecimalFromInteger(150);
x.minorTicksPerInterval = 5;
x.axisConstraints = [CPTConstraints constraintWithLowerOffset:0.0f];
x.labelingPolicy=CPTAxisLabelingPolicyNone;
NSUInteger labelLocation = 0;
NSMutableArray *customLabels = [NSMutableArray arrayWithCapacity:[objects count]];
NSMutableSet *xMajorLocations = [NSMutableSet setWithCapacity:[objects count]];
for (NSInteger i = 0; i < [objects count]; i++) {
NSManagedObject *theLine = [objects objectAtIndex:i];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
NSString *sPeriodText = @"";
[dateFormatter setDateFormat:@"MMMM yyyy"];
sPeriodText = [dateFormatter stringFromDate:[theLine valueForKey:@"period_start"]];
CPTAxisLabel *newLabel = [[CPTAxisLabel alloc] initWithText:sPeriodText textStyle:labelTextStyle];
newLabel.tickLocation = CPTDecimalFromInteger(labelLocation++);
newLabel.offset = x.labelOffset + x.majorTickLength;
[customLabels addObject:newLabel];
[xMajorLocations addObject:[NSNumber numberWithFloat:labelLocation-1]];
}
x.axisLabels = [NSSet setWithArray:customLabels];
x.majorTickLocations = xMajorLocations;
谢谢!
PS 我试图使用 CPTAxis 的 labelExclusionRanges,但它不适用于自定义标签。