我在我的应用程序中实现了散点图的核心绘图库。但我想显示 Y 轴标签,如 1.0、2.0、3.0、4.0、5.0,.. 并相应地绘制图表。
当我如下所示乘以 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 分。
最佳答案
您可以设置 orthogonalCoordinateDecimal,以确定图形开始的点
CPTXYAxis *y = axisSet.yAxis;
y.orthogonalCoordinateDecimal = CPTDecimalFromFloat(150/25);
进一步,设置plotRange,
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace;
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:(150/25) length:25];
关于iphone - 更改核心图中的 y 轴标签间隔,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13305116/