我试图在 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 轴网格线(即垂直网格线)没有出现。只看到水平网格线,您可以在下面的 App 截图中看到: