核心图:标签策略不是自动时,不会出现网格线

Jea*_*ean 0 core-plot ios

我试图在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];
Run Code Online (Sandbox Code Playgroud)

但是,因为当我为X轴添加自定义标签时,X轴网格线(即垂直线)没有出现.只能看到水平网格线,您可以在App的下方屏幕截图中看到:

在此输入图像描述

Eri*_*och 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;
Run Code Online (Sandbox Code Playgroud)

刻度线位置通常与标签位置相同,但它们不一定相同.