我在我的一個iPhone項目中使用了核心圖。是否可以更改餅圖中選定切片的顏色(使用CPPieChartDataSource,CPPieChartDelegate)?Core-Plot PieChart Slice color
10
A
回答
18
在餅圖數據源實現以下方法:
-(CPTFill *)sliceFillForPieChart:(CPTPieChart *)pieChart recordIndex:(NSUInteger)index;
CPFill可以是顏色,圖像,或梯度。
5
在您的.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;
}
它將改變餅圖切片的顏色。謝謝
1
我將此添加到我的.m文件(這是餅圖的數據源文件)。顏色很醜 - 只是用它們來測試,因爲它們與默認設置完全不同。我的圖表中只有三個切片,因此是硬編碼的三種顏色。我發現Core Plot文檔對所有這些都有幫助。 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;
}
很抱歉,如果我搞砸了答案項 - 這是我第一次張貼在計算器上
0
斯威夫特版本:
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());
}
}
相關問題
- 1. 如何在PieChart中給每個片段命名Coreplot iphone?
- 2. 警告而CorePlot
- 3. Piechart中的Piechart楔形邊框樣式
- 4. div class change color from color name to color #code
- 5. IndexError:invalid slice
- 6. Javafx更改PieChart顏色
- 7. MPAndroidChart PieChart角度
- 8. pieChart pieSliceText visibilty
- 9. 動畫Piechart fillmode?
- 10. PieChart與標籤
- 11. iPhone Coreplot
- 12. Kotlin lazy slice array
- 13. numpy slice assignment
- 14. Numpy slice to indices
- 15. slice/stride by variable?
- 16. xcode:NSArray slice方法?
- 17. dropzone.js:__slice = [] .slice
- 18. .slice和.wrapall
- 19. Mediawiki:font color
- 20. 正則表達式換行$ {color}和$ color
- 21. 點上CorePlot圖
- 22. ios coreplot設置
- 23. CorePlot - iPhone圖表
- 24. iOS中的CorePlot
- 25. coreplot multiple axis
- 26. Coreplot - 梯度
- 27. CorePlot的曲線
- 28. Coreplot安裝
- 29. CorePlot stipes填充
- 30. 創建CorePlot圖
我想,當它改變特定切片的顏色被選中。那可能嗎? – random 2010-09-03 04:06:04
如何添加圖像? – ravoorinandan 2011-04-28 15:56:15
我猜它現在是CPTFill和CPTPieChart .. – TechnocraT 2012-03-14 13:03:56