Tôi đang sử dụng cốt truyện cốt lõi trong một trong các dự án iPhone của mình. Có thể thay đổi màu sắc cho một lát được chọn trong biểu đồ hình tròn (sử dụng CPPieChartDataSource, CPPieChartDelegate) không?Core-Plot PieChart Slice color
Trả lời
Thực hiện các phương pháp sau đây trong nguồn dữ liệu biểu đồ pie của bạn:
-(CPTFill *)sliceFillForPieChart:(CPTPieChart *)pieChart recordIndex:(NSUInteger)index;
CPFill có thể là một màu sắc, hình ảnh, hoặc gradient.
Trong file .h của bạn
#import "CPTPieChart.h"
@interface YourViewController : UIViewController<CPTPlotDataSource,CPTPieChartDataSource, CPTPieChartDelegate>
{
}
trong file .m bạn
-(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;
}
Nó sẽ thay đổi màu sắc PieChart Slice. Cảm ơn
Tôi đã thêm tệp này vào tệp .m của tôi (là tệp nguồn dữ liệu cho biểu đồ hình tròn). Các màu sắc xấu xí - chỉ cần sử dụng chúng để kiểm tra vì chúng thực sự khác với các giá trị mặc định. Và chỉ có ba lát trong biểu đồ của tôi, do đó có 3 màu được mã hóa cứng. Tôi thấy tài liệu Core Plot hữu ích cho tất cả điều này. Here's the link to the fillWithColor method documentation. LƯU Ý: Bạn cần sử dụng CPT làm tiền tố ngay bây giờ, không phải CP cũ.
-(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;
}
Xin lỗi nếu tôi sai lầm mục câu trả lời - đây là đầu tiên của tôi bao giờ đăng bài trên StackOverflow
phiên bản 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());
}
}
- 1. CSS "color" so với "font-color"
- 2. Sự khác biệt giữa "-webkit-text-fill-color" và "color"?
- 3. Chỉ mục slice chuỗi Python - slice đến cuối chuỗi
- 4. iPhone CorePlot định dạng đúng trục y
- 5. Chạm vào ô plotSymbol trong CorePlot
- 6. PreferenceFragment background color
- 7. UIProgressView unprogressed color
- 8. Android ImageButton background color
- 9. jQuery: Color fade
- 10. UITextField clearButtonMode color
- 11. Slice image wpf
- 12. [] .slice hoặc Array.prototype.slice
- 13. Thay đổi tr background-color
- 14. Animate Shape Color trong Android
- 15. Thay đổi Polyline Color Dynamically
- 16. PHPExcel: Cách lấy CELL COLOR
- 17. jquery flot pie slice màu
- 18. số django slice trong mẫu
- 19. Ký hiệu slice ở Scala?
- 20. Slice Pandas DataFrame by Row
- 21. Moz-use-text-color là gì?
- 22. NSIS visual studio color/font/intellisense
- 23. Color "trong suốt" không làm việc
- 24. Làm thế nào nhanh là slice python
- 25. kiểu, định dạng toán tử slice
- 26. itertools.islice so với danh sách slice
- 27. [python]: cách triển khai slice trong python3?
- 28. python tạo đối tượng slice từ chuỗi
- 29. Index và Slice một Generator bằng Python
- 30. Regexp Matching Hex Color Syntax (và Shorten form)
Tôi muốn thay đổi màu sắc của một lát đặc biệt khi nó đã được chọn. Điều đó có thể không? – random
cách thêm hình ảnh? – ravoorinandan
Tôi đoán bây giờ CPTFill và CPTPieChart của nó thay thế .. – TechnocraT