【问题标题】:display same color of text label as pie chart slice have显示与饼图切片相同颜色的文本标签
【发布时间】:2011-05-18 11:25:58
【问题描述】:

我正在使用核心图绘制饼图和以下文本

错误 10
通过 400

所以对于上述数据,我的饼图包含 2 个具有 2 种不同颜色的切片

我想为每个切片设置相同的文本颜色

现在文字是白色的

谢谢你

【问题讨论】:

    标签: iphone objective-c graph colors core-plot


    【解决方案1】:

    @pooja 我明白了 :) 在不实施的情况下试试这个

    -sliceFillForPieChart:recordIndex:
    -(CPLayer *)dataLabelForPlot:(CPPlot *)plot recordIndex:(NSUInteger)index 
    {
    
    CPTextLayer *label = [[CPTextLayer alloc] initWithText:[NSString stringWithFormat:@"%i", index]];
    CPMutableTextStyle *textStyle = [label.textStyle mutableCopy];
    textStyle.color = [CPPieChart defaultPieSliceColorForIndex:index];
    label.textStyle = textStyle;
    [textStyle release];
    return [label autorelease];
    }
    

    【讨论】:

    • @Samar,你有没有用核心图绘制折线图的经验
    • @pooja ,我之前做过一个..你有什么问题?
    • 我想画折线图,y轴有数字,x轴有时间,所以如何计算x轴上的时间,把x轴范围是24小时周期,我可以绘制我的折线图现在我很困惑如何计算 hr+min+second 并画线
    • @pooja,您可以按照 dateplot 示例进行操作。我认为它会对您有所帮助
    • @pooja,没问题..如果您有任何问题,请告诉我
    【解决方案2】:

    您可以使用绘图的labelTextStyle 属性来更改标签的外观。

    【讨论】:

    • 是的,但是如何与颜色相关,因为我不知道哪个切片将绘制或填充哪种颜色......所以切片有颜色假设红色,所以我的文本颜色也应该是红色和其他切片有绿色,所以文本将是绿色的
    • 我可以显示标签,但与切片颜色不同,你能给我举个例子吗,标签颜色与切片颜色相同
    • 您需要在数据源中实现-sliceFillForPieChart:recordIndex:-sliceLabelForPieChart:recordIndex: 方法。对切​​片标签中使用的填充和文本样式使用相同的颜色。
    • @Eric,以下是我的代码 -(CPLayer *)sliceLabelForPieChart:(CPPieChart *)pieChart recordIndex:(NSUInteger)index { NSString *test=[NSString stringWithFormat:@"%@",[pieValueArray objectAtIndex:pieValueIndex]];饼值索引++; CPTextLayer *label = [[CPTextLayer alloc] initWithText:test]; CPMutableTextStyle *textStyle = [label.textStyle mutableCopy]; textStyle.color = [CPColor lightGrayColor];标签.textStyle = textStyle; [文本样式发布];返回[标签自动释放]; } 但我仍然无法看到任何标签,即使没有 lightGrayColor
    • @Eric,我可以看到带有 -(CPLayer *)dataLabelForPlot:(CPPlot *)plot recordIndex:(NSUInteger)index { NSString *test=[NSString stringWithFormat:@"%@",[ pieValueArray objectAtIndex:pieValueIndex]];饼值索引++; CPTextLayer *label = [[CPTextLayer alloc] initWithText:test];//这里放值 CPMutableTextStyle *textStyle = [label.textStyle mutableCopy]; textStyle.color = [CPColor lightGrayColor];标签.textStyle = textStyle; [文本样式发布];返回[标签自动释放]; } 标签是显示的,但只有 lightGrayColor
    猜你喜欢
    • 2015-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多