0

我在我的应用程序中实现了散点图的核心绘图库。但我想显示 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=6th 点。

4

1 回答 1

2

您可以设置正交坐标小数点,以确定图表开始的点

 CPTXYAxis *y = axisSet.yAxis;
   y.orthogonalCoordinateDecimal = CPTDecimalFromFloat(150/25);

更进一步,设置情节范围,

 CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace;   
   plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:(150/25) length:25];
于 2012-11-09T09:37:00.233 回答