アプリに散布図のコア プロット ライブラリを実装しました。しかし、私は 1.0,2.0,3.0,4.0,5.0,.. のような Y 軸ラベルを表示し、それに応じてグラフをプロットしたいと考えています。
以下に示すように、25を掛けてyラベルの間隔を次のように変更すると
NSInteger majorIncrement = 2;
NSInteger minorIncrement = 1;
CGFloat yMax = 10.0f;// should determine dynamically based on max price
NSMutableSet *yLabels = [NSMutableSet set];
NSMutableSet *yMajorLocations = [NSMutableSet set];
NSMutableSet *yMinorLocations = [NSMutableSet set];
for (NSInteger j = minorIncrement; 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*25); **//multiply with 25**`
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;
しかし、グラフをプロットすると、間違っていることがわかります。
たとえば、スコアが 150 の場合、プロットは 150/25=6 番目のポイントとして開始されます。