0

アプリに散布図を追加し、配列 cogsetUsed (つまり、自転車のコグセット) に含まれる項目を X 軸のラベルに表示したいと考えています。アイテムの数は 8 から 11 までです。

私が得るものは次のとおりです。

画面キャプチャ

これはコードの一部です:

CPTGraph *graph = self.hostView.hostedGraph;
CPTXYAxisSet *axisSet = (CPTXYAxisSet *)graph.axisSet;

CPTXYAxis *x = axisSet.xAxis;

x.visibleRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInteger(0) length:CPTDecimalFromInteger(12)];
x.labelingPolicy = CPTAxisLabelingPolicyNone;
x.labelTextStyle = axisTextStyle;
x.majorTickLineStyle = axisLineStyle;
x.majorTickLength =4.0f;
x.tickDirection =CPTSignNegative;
CGFloat recordCount = [cogsetUsed count];
NSMutableSet *xLabels =[NSMutableSet setWithCapacity:recordCount];
NSMutableSet *xLocations = [NSMutableSet setWithCapacity:recordCount];
NSInteger i =0;
for (NSString *sprocket in cogsetUsed) {
    CPTAxisLabel *label = [[CPTAxisLabel alloc] initWithText:sprocket  textStyle:x.labelTextStyle];
    CGFloat location = i++;
    label.tickLocation = CPTDecimalFromCGFloat(location);
    label.offset =x.majorTickLength;
    if (label) {
        [xLabels addObject:label];
        [xLocations addObject:[NSNumber numberWithFloat:location]];
    }
}
x.axisLabels = xLabels;
x.majorTickLocations = xLocations;

ご協力いただきありがとうございます!

4

1 に答える 1

0

Core Plot は、ラベル間の衝突を防ぎません。すべての目盛りにラベルを付ける必要はありません。とにかくカスタムの軸ラベルを作成しているので、すべての目盛りの位置にラベルを付けないでください。見栄えを良くするために、3 番目または 4 番目のティックごとにラベルを付けることができるようです。

于 2012-12-05T01:07:16.030 に答える