Iphone 如何将标签添加到CPBarPlot BarPlot?

Iphone 如何将标签添加到CPBarPlot BarPlot?,iphone,core-plot,Iphone,Core Plot,我对Core Plot完全不熟悉,有一个工作条形图,但视觉效果对我来说毫无用处,除非我知道每个条形图中代表的是哪个对象。我已经看到有一个名为“fieldIdentifiers”的方法,但不知道如何实现它,也找不到任何文档(如果这是正确的方法)。你能把我引向正确的方向吗?谢谢 要手动设置核心绘图图中某个轴的标签,需要将该轴的labelingPolicy设置为CPAxisLabelingPolicyNone,然后自己提供标签。例如,以下代码将在条形图中设置自定义标签(从我将在某个时候添加到iPhon

我对Core Plot完全不熟悉,有一个工作条形图,但视觉效果对我来说毫无用处,除非我知道每个条形图中代表的是哪个对象。我已经看到有一个名为“fieldIdentifiers”的方法,但不知道如何实现它,也找不到任何文档(如果这是正确的方法)。你能把我引向正确的方向吗?谢谢

要手动设置核心绘图图中某个轴的标签,需要将该轴的labelingPolicy设置为
CPAxisLabelingPolicyNone
,然后自己提供标签。例如,以下代码将在条形图中设置自定义标签(从我将在某个时候添加到iPhone示例应用程序的代码中提取):


这将在X轴上的位置1、5、10、15和20处设置五个自定义标签(标签A、B、C、D和E)。

您是我的英雄。我能够将您编写的内容合并到我的代码中,生成一个美味的label-y图表。您是否使用了新功能来设置条形图顶部的标签?它在Mac的CPTestApp中,但对我来说是不透明的。Drew几天前刚刚添加了这一点,我不太明白它是如何工作的。它与-barLabelForBarPlot:recordIndex:delegate方法有关,但我无法在代码中复制这种效果。嗨,如果手动为axis设置标签,当barplots的值发生更改时,axislabels的位置会受到干扰。如何解决此问题?
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];