Iphone 核心图饼图切片颜色
我正在我的一个iPhone项目中使用core plot。是否可以更改饼图中选定切片的颜色(使用CPPieChartDataSource、CPPieChartDelegate)?在饼图数据源中实现以下方法:Iphone 核心图饼图切片颜色,iphone,core-plot,Iphone,Core Plot,我正在我的一个iPhone项目中使用core plot。是否可以更改饼图中选定切片的颜色(使用CPPieChartDataSource、CPPieChartDelegate)?在饼图数据源中实现以下方法: -(CPTFill *)sliceFillForPieChart:(CPTPieChart *)pieChart recordIndex:(NSUInteger)index; CPFill可以是颜色、图像或渐变。在.h文件中 #import "CPTPieChart.h" @interfa
-(CPTFill *)sliceFillForPieChart:(CPTPieChart *)pieChart recordIndex:(NSUInteger)index;
CPFill可以是颜色、图像或渐变。在.h文件中
#import "CPTPieChart.h"
@interface YourViewController : UIViewController<CPTPlotDataSource,CPTPieChartDataSource, CPTPieChartDelegate>
{
}
它将改变图表切片的颜色。谢谢我将其添加到我的.m文件(饼图的数据源文件)。这些颜色很难看——只是用它们来测试,因为它们与默认值确实不同。在我的图表中只有三个部分,因此是硬编码的三种颜色。我发现核心绘图文档对所有这些都很有帮助。注意:您现在需要使用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上发表文章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());
}
}
我想在选定特定切片时更改其颜色。可能吗?
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());
}
}