CPTBarPlot:繪制柱狀圖(有水平和垂直兩種)
建議閱讀以下內(nèi)容時(shí)琉预,同時(shí)參看GitHub上coreplot自帶的工程例子。
補(bǔ)充繪圖的幾個(gè)大步驟蒿褂,使用coreplot的繪制柱狀圖/餅圖或其他圖圆米,都是一樣的:
1卒暂、配置CPTGraphHostingView,加載在self.view上
2娄帖、配置CPTGraph (含Theme也祠、padding、title块茁、PlotSpace等)
3、配置畫布(CPTGraph)的XY軸的式樣
4桂肌、配置CPTBarPlot 或 CPTPieChart 或CPTScatterPlot等
柱狀圖基礎(chǔ)用法:
1数焊、設(shè)置柱狀的線條式樣lineStyle
2、柱子的填充色
3崎场、增加柱狀注釋
CPTPlotSpaceAnnotation *legendAnnotation佩耳;
CPTLegend *theLegend;
legendAnnotation.contentLayer = theLegend;
[graph.plotAreaFrame.plotArea addAnnotation:legendAnnotation];
代理事件:
//點(diǎn)擊柱條上部的文字值
-(void)plot:(CPTPlot *)plot dataLabelWasSelectedAtRecordIndex:(NSUInteger)index
//點(diǎn)擊柱條(可以點(diǎn)擊柱條后展示數(shù)值)
-(void)barPlot:(CPTBarPlot *)plot barWasSelectedAtRecordIndex:(NSUInteger)index
//X和Y軸谭跨,需要展示的刻度的值干厚,每一個(gè)柱條的數(shù)值
-(id)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index
繪制柱狀圖時(shí)可以全部展示每個(gè)柱條的文字,也可以不展示螃宙,點(diǎn)擊柱條時(shí)才展示蛮瞄。