我对 Core Plot 完全陌生,并且有一个可用的条形图,但视觉效果对我来说有点无用,除非我知道每个条形中代表哪个对象。我看到有一个名为“fieldIdentifiers”的方法,但不知道如何实现它,也找不到任何文档(如果这甚至是正确的方法)。你能引导我走向正确的方向吗?谢谢!
为了手动设置 Core Plot 图表中轴的标签,您需要将该轴的 labellingPolicy 设置为CPAxisLabelingPolicyNone
并自行提供标签。例如,以下代码将在条形图中设置自定义标签(从我将在某个时候添加到 iPhone 示例应用程序的代码中绘制):
CPXYAxisSet *axisSet = (CPXYAxisSet *)barChart.axisSet;
CPXYAxis *x = axisSet.xAxis;
x.labelRotation = M_PI/4;
x.labelingPolicy = CPAxisLabelingPolicyNone;
NSArray *customTickLocations = [NSArray arrayWithObjects:[NSDecimalNumber numberWithInt:1], [NSDecimalNumber numberWithInt:5], [NSDecimalNumber numberWithInt:10], [NSDecimalNumber numberWithInt:15], [NSDecimalNumber numberWithInt:20], nil];
NSArray *xAxisLabels = [NSArray arrayWithObjects:@"Label A", @"Label B", @"Label C", @"Label D", @"Label E", nil];
NSUInteger labelLocation = 0;
NSMutableArray *customLabels = [[NSMutableArray alloc] initWithCapacity:[xAxisLabels count]];
for (NSNumber *tickLocation in customTickLocations)
{
CPAxisLabel *newLabel = [[CPAxisLabel alloc] initWithText: [xAxisLabels objectAtIndex:labelLocation++] textStyle:x.labelTextStyle];
newLabel.tickLocation = [tickLocation decimalValue];
newLabel.offset = x.labelOffset + x.majorTickLength;
newLabel.rotation = M_PI/4;
[customLabels addObject:newLabel];
[newLabel release];
}
x.axisLabels = [NSSet setWithArray:customLabels];
这将在 X 轴上的位置 1、5、10、15 和 20 处设置五个自定义标签(标签 A、B、C、D 和 E)。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)