0

アプリに散布図のコア プロット ライブラリを実装しました。しかし、私は 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 番目のポイントとして開始されます。

4

1 に答える 1

2

直交座標デシマルを設定できます, グラフの開始点を決定するために

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

さらに、plotRange を設定し、

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