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

Adding labels to pie chart in CorePlot: no idea how

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

您能否建议我将什么代码添加到我的图形中以便在三角形内添加标签?我试过的代码如下:

-(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;
}

但是我得到的结果有不在三角形中的标签:


我实现了数据标签

"Simple Pie Chart" 演示中的自定义图例条目标签由 -attributedLegendTitleForPieChart:recordIndex: 数据源方法提供。如果您不需要标签中的属性文本,您可以使用 -legendTitleForPieChart:recordIndex: 方法代替。