在我的图表中,majorGridLines 适用于整数,但当范围在 3.0 和 0.0 之间时,majorTickLocations 大约有 10 个。刻度位置在正确的位置,IE 大约每 0.3 次,但 majorGridLines 与 Tick 的位置不同,它们只是落在整数 1.0、2.0、3.0 等上。我怎样才能得到 majorGridLines使用非整数并与 tickLocations 保持一致?
代码如下:
NSMutableSet *yLabels = [NSMutableSet set];
NSMutableSet *yMajorLocations = [NSMutableSet set];
for (int i=-1; i<numYAxisLabels; i++) {
id jAsID = [NSNumber numberWithInt:(int)j];
int jAsInt = [jAsID integerValue];
CPTAxisLabel *label;
if(majorIncrement < 1)
label = [[CPTAxisLabel alloc] initWithText:[NSString stringWithFormat:@"%.1f", j] textStyle:y.labelTextStyle];
else
label = [[CPTAxisLabel alloc] initWithText:[NSString stringWithFormat:@"%d", jAsInt] textStyle:y.labelTextStyle];
NSDecimal location = CPTDecimalFromFloat(j);
label.tickLocation = location;
label.offset = -y.majorTickLength - y.labelOffset;
[yLabels addObject:label];
[yMajorLocations addObject:jAsID];
currTopYLabelLocation = j;
j += majorIncrement;
}
y.axisLabels = yLabels;
y.majorTickLocations = yMajorLocations;