我有一個使用core-plot
框架的圖,它的Y軸最低值大概是155左右。我想這樣做是爲了讓155開始在圖底部,正好對着X軸。core-plot iOS:如何讓圖形從底部開始一定量?
這是我爲Y軸代碼:
NSInteger majorIncrement = 1;
NSInteger minorIncrement = 1;
CGFloat yMax = [[prices valueForKeyPath:@"@max.self"] doubleValue]; // should determine dynamically based on max price
NSMutableSet *yLabels = [NSMutableSet set];
NSMutableSet *yMajorLocations = [NSMutableSet set];
NSMutableSet *yMinorLocations = [NSMutableSet set];
for (NSInteger j = [[prices valueForKeyPath:@"@min.self"] doubleValue]; j <= yMax; j += minorIncrement) {
NSUInteger mod = j % majorIncrement;
if (mod == 0) {
CPTAxisLabel *label = [[CPTAxisLabel alloc] initWithText:[NSString stringWithFormat:@"%i", j] textStyle:y.labelTextStyle];
NSDecimal location = CPTDecimalFromInteger(j);
label.tickLocation = location;
label.offset = -y.majorTickLength - y.labelOffset;
if (label) {
[yLabels addObject:label];
}
[yMajorLocations addObject:[NSDecimalNumber decimalNumberWithDecimal:location]];
} else {
[yMinorLocations addObject:[NSDecimalNumber decimalNumberWithDecimal:CPTDecimalFromInteger(j)]];
}
}
y.axisLabels = yLabels;
y.majorTickLocations = yMajorLocations;
y.minorTickLocations = yMinorLocations;
非常感謝您!這工作! – Burrito411