代码之家  ›  专栏  ›  技术社区  ›  random

芯线图压电片颜色

  •  10
  • random  · 技术社区  · 15 年前

    我正在我的一个iPhone项目中使用核心情节。是否可以更改饼图中选定切片的颜色(使用cppiechartDatasource、cppiechartDelegate)?

    4 回复  |  直到 15 年前
        1
  •  18
  •   jab    11 年前

    在饼图数据源中实现以下方法:

    -(CPTFill *)sliceFillForPieChart:(CPTPieChart *)pieChart recordIndex:(NSUInteger)index; 
    

    cpfill可以是颜色、图像或渐变。

        2
  •  5
  •   chandan    13 年前

    在.h文件中

    #import "CPTPieChart.h"
    @interface YourViewController : UIViewController<CPTPlotDataSource,CPTPieChartDataSource, CPTPieChartDelegate>
    {   
    }
    

    在.m文件中

    -(CPTFill *)sliceFillForPieChart:(CPTPieChart *)pieChart recordIndex:(NSUInteger)index
    {    
        CPTFill *areaGradientFill ;
    
        if (index==0)
            return areaGradientFill= [CPTFill fillWithColor:[CPTColor orangeColor]];
        else if (index==1)
            return areaGradientFill= [CPTFill fillWithColor:[CPTColor greenColor]];
        else if (index==2)
            return areaGradientFill= [CPTFill fillWithColor:[CPTColor yellowColor]];
    
        return areaGradientFill;
    }
    

    它将改变压纹图切片的颜色。谢谢

        3
  •  1
  •   Mike Critchley    11 年前

    我把它添加到我的.m文件中(这是饼图的数据源文件)。颜色很难看——只是用它们来测试,因为它们与默认值确实不同。我的图表只有三个部分,因此硬编码的3种颜色。我发现核心绘图文档对所有这些都有帮助。 Here's the link to the fillWithColor method documentation . 注意:现在需要使用cpt作为前缀,而不是旧的cp。

    -(CPTFill *)sliceFillForPieChart:(CPTPieChart *)pieChart recordIndex:(NSUInteger)index;
      {
         CPTFill *color;
    
         if (index == 0) {     
          color = [CPTFill fillWithColor:[CPTColor purpleColor]]; 
    
        } else if (index == 1) {
          color = [CPTFill fillWithColor:[CPTColor blueColor]];
    
    
        } else {
          color = [CPTFill fillWithColor:[CPTColor blackColor]];
                }
    
            return color;
     }
    

    抱歉,如果我把答案条目弄乱了--这是我第一次在StackOverflow上发表文章

        4
  •  0
  •   Sheldon Barnes    11 年前

    SWIFT版:

    func sliceFillForPieChart (pieChart: CPTPieChart, recordIndex: UInt) -> CPTFill {
        switch (recordIndex+1) {
        case 1:
            return CPTFill(color:CPTColor.greenColor());
        case 2:
    
            return CPTFill(color:CPTColor.redColor());
        default:
            return CPTFill(color:CPTColor.orangeColor());
        }
    
    }