CPTPieChart:繪制餅圖
建議閱讀以下內(nèi)容時茂腥,同時參看GitHub上coreplot自帶的工程例子。
CPTGraph的屬性axisSet需要置為nil(即不需要展示坐標軸)
基本屬性:
pieRadius:半徑
startAngle:開始繪制的偏移(只是圓沿著中心旋轉(zhuǎn)了以下)
endAngle
sliceDirection:餅圖按照逆時針繪制
centerAnchor:重心
overlayFill:餅圖的陰影/光澤效果(建議設(shè)置為nil)
shadow:陰影效果
pieInnerRadius:類似于讓餅圖空心的半徑
//餅圖文字展示方向和位置
piePlot.labelRotationRelativeToRadius = YES;//文字是否順著圖形的方向
piePlot.labelRotation = CPTFloat(-M_PI_2);
piePlot.labelOffset = -50.0;
設(shè)置好數(shù)據(jù)源plotData后仍劈,reloadData刷新界面。
代理方法:
//返回扇形數(shù)目(其他兩個圖形也有,例如折線圖表示折點個數(shù))
- (NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot
//返回每個扇形的比例(其他兩個圖形也有妙色,意義不同)
- (NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)idx
//返回每個扇形的標題(可以為比重 / 內(nèi)容)
- (CPTLayer *)dataLabelForPlot:(CPTPlot *)plot recordIndex:(NSUInteger)idx
//條目 / 圖例說明文字(餅圖和柱狀圖有該代理)CPTLegend的代理
- (NSAttributedString *)attributedLegendTitleForPieChart:(CPTPieChart *)pieChart recordIndex:(NSUInteger)idx
高級用法
代理:
//繪制某一扇形是的顏色
-(CPTFill *)sliceFillForPieChart:(CPTPieChart *)pieChart recordIndex:(NSUInteger)idx
//第index扇形突出展示
-(CGFloat)radialOffsetForPieChart:(CPTPieChart *)pieChart recordIndex:(NSUInteger)index
//點擊餅圖的某一個部分事件
-(void)pieChart:(CPTPieChart *)plot sliceWasSelectedAtRecordIndex:(NSUInteger)index