カスタムラベルを使用していますが、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を使用しようとしましたが、カスタムラベルでは機能しませんでした。