0

iPhone アプリで Core Plot を使用して単純な統計をプロットしようとしています。私は最初、ラベル付けポリシーを両方の軸に CPTAxisLabelingPolicyAutomatic として使用しました。グリッド線は次のようにうまく表示されました。

ここに画像の説明を入力

グラフに垂直と水平の両方のグリッド ラインがあることがわかります。次に、ラベル付けポリシーを次のように変更しました

    axisSet.xAxis.labelingPolicy = CPTAxisLabelingPolicyNone;
    axisSet.yAxis.labelingPolicy = CPTAxisLabelingPolicyAutomatic;

NSUInteger labelLocation = 0;
NSMutableArray *customLabels = [NSMutableArray arrayWithCapacity:xAxisLabels.count];
CPTMutableTextStyle *textStyle = [[CPTMutableTextStyle alloc] init];
textStyle.color = [CPTColor lightGrayColor];

for (NSNumber *tickLocation in customTickLocations) {
    CPTAxisLabel *newLabel = [[CPTAxisLabel alloc]
                              initWithText:[NSString stringWithFormat:@"%@",(NSDate *)[xAxisLabels objectAtIndex:labelLocation++]] textStyle:textStyle];
    newLabel.tickLocation = [tickLocation decimalValue];
    newLabel.rotation = 25.0;
    newLabel.offset = 10.0;
    [customLabels addObject:newLabel];
}
axisSet.xAxis.axisLabels =  [NSSet setWithArray:customLabels];

しかし、X 軸にカスタム ラベルを追加したため、X 軸のグリッド線 (垂直線) が表示されません。以下のアプリのスクリーンショットでわかるように、水平のグリッド線のみが表示されます。

ここに画像の説明を入力

4

2 に答える 2

8

ラベル付けポリシーでは、CPTAxisLabelingPolicyNoneラベルや目盛りは作成されません。場所のセットを作成し、majorTickLocationsおよび/またはを設定する必要がありますminorTickLocations

Plot Galleryサンプル アプリのサンプル コードを次に示します。

NSSet *majorTickLocations = [NSSet setWithObjects:[NSDecimalNumber zero],
                             [NSDecimalNumber numberWithUnsignedInteger:30],
                             [NSDecimalNumber numberWithUnsignedInteger:50],
                             [NSDecimalNumber numberWithUnsignedInteger:85],
                             [NSDecimalNumber numberWithUnsignedInteger:100],
                             nil];
xAxis.majorTickLocations = majorTickLocations;

多くの場合、目盛りの位置はラベルの位置と同じですが、そうである必要はありません。

于 2013-05-22T23:27:49.640 に答える