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