在CorePlot中向饼图添加标签:不知道如何

时间:2015-08-25 14:42:10

标签: ios graph customization core-plot labels

我正在使用CorePlot for iOS,我喜欢这个图表示例,但我无法在我的图表上做同样的事情。

enter image description here

您是否可以建议我添加到图表中的代码,以便在三角形内添加标签?我尝试的代码如下:

-(CPTLayer *)dataLabelForPlot:(CPTPlot *)plot recordIndex:(NSUInteger)index
{
    NSNumber * dataForItem = [self.dataForChart objectAtIndex:index];

    if ( [plot isKindOfClass:[CPTPieChart class]]){
        return  [[CPTTextLayer alloc] initWithText:[NSString stringWithFormat:@"%@", dataForItem]];
    }
    else return nil;
}

然而,我得到的结果的标签不在三角形中:

enter image description here

我实现了dataLabel

1 个答案:

答案 0 :(得分:1)

"简单饼图"中的自定义图例条目标签演示由-attributedLegendTitleForPieChart:recordIndex:数据源方法提供。如果您不需要标签中的归属文字,则可以使用-legendTitleForPieChart:recordIndex:方法。