我在我的一個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. 使用CorePlot更改PieChart的borderLineStyle
- 2. pieChart動畫
- 3. 如何在PieChart中給每個片段命名Coreplot iphone?
- 4. 警告而CorePlot
- 5. Android PieChart使用AChartEngine
- 6. div class change color from color name to color #code
- 7. Piechart中的Piechart楔形邊框樣式
- 8. IndexError:invalid slice
- 9. Javafx更改PieChart顏色
- 10. DrawableCompat.setTint(drawable,color)vs Drawable.setColorFilter(color,mode)
- 11. JQuery slice()或each()的性能?
- 12. MPAndroidChart PieChart角度
- 13. cakePHP- PieChart Helper類
- 14. pieChart pieSliceText visibilty
- 15. PieChart與標籤
- 16. 動畫Piechart fillmode?
- 17. iPhone Coreplot
- 18. Coreplot scaletofitplotissue
- 19. CorePlot 1.5.1中的錯誤
- 20. JavaScript .substr()和.slice()
- 21. Kotlin lazy slice array
- 22. dropzone.js:__slice = [] .slice
- 23. numpy slice assignment
- 24. Numpy slice to indices
- 25. .slice和.wrapall
- 26. slice/stride by variable?
- 27. jQuery .Slice澄清
- 28. DICOM Slice Ordering
- 29. [] .slice或Array.prototype.slice
- 30. xcode:NSArray slice方法?
我想,當它改變特定切片的顏色被選中。那可能嗎? – random 2010-09-03 04:06:04
如何添加圖像? – ravoorinandan 2011-04-28 15:56:15
我猜它現在是CPTFill和CPTPieChart .. – TechnocraT 2012-03-14 13:03:56