我试图在iPhone App中使用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截图屏幕截图所示:
答案 0 :(得分: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;
刻度线位置通常与标签位置相同,但不一定是。
答案 1 :(得分:3)
谢谢你,@ Erik Skroch!对我有用的是标签政策的简单改变
axisSet.xAxis.labelingPolicy = CPTAxisLabelingPolicyNone;
到
axisSet.xAxis.labelingPolicy = CPTAxisLabelingPolicyFixedInterval;
这是由你的声明煽动的: “CPTAxisLabelingPolicyNone标签政策不会创建任何标签或刻度线。”