【问题标题】:defaultPieSliceColorForINdex:index not returning proper color value: coreplotdefaultPieSliceColorForINdex:索引未返回正确的颜色值:coreplot
【发布时间】:2012-05-23 12:49:35
【问题描述】:

我正在尝试使用下面的委托方法来绘制数据标签

-(CPTLayer *) dataLabelForPlot:(CPTPlot *)plot recordIndex:(NSUInteger)index
{  
    CPTTextLayer *label = [[CPTTextLayer alloc] initWithText:
        [NSString stringWithFormat:@"%u", index]];  
    CPTMutableTextStyle *textStyle = [label.textStyle mutableCopy];  
    textStyle.color = [CPTPieChart defaultPieSliceColorForIndex:index];  
    label.textStyle=textStyle;  
    return label;  
}  

我得到的输出是这样的:

所以你可以看到差异:

  • slice 0 数据标签为红色,但应为黄色。
  • slice 3 数据标签为黄色,但应为洋红色。

我可以通过switch(index) 实现这一点,但为什么它不能这样工作呢?
有什么建议吗?

【问题讨论】:

    标签: iphone core-plot pie-chart


    【解决方案1】:

    标签是正确的颜色 - 与默认颜色不匹配的是饼图。其他数据源方法返回什么值?

    默认颜色为:

    索引 RGB 颜色 ------------------------------------------ 0 (1.0, 0.0, 0.0) 红色 1 (0.0, 1.0, 0.0) 绿色 2 (0.0, 0.0, 1.0) 蓝色 3 (1.0, 1.0, 0.0) 黄色 4 (0.25, 0.5, 0.25) 深绿色 5 (1.0, 0.0, 1.0) 洋红色 6 (0.5, 0.5, 0.5) 灰色 7 (0.25, 0.5, 0.0) 中绿色 8 (0.25, 0.25, 0.25) 深灰色 9 (0.0, 1.0, 1.0) 青色

    【讨论】:

    • 感谢您的回复!我的愚蠢我认为 defaultPieSliceColorForIndex:index 会自动将切片的默认颜色返回到数据标签颜色。我在 sliceForPieChart 委托方法中控制每个饼切片颜色。感谢您的补充信息。:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-14
    • 1970-01-01
    • 2015-09-02
    • 2017-07-31
    • 1970-01-01
    相关资源
    最近更新 更多