A UIView For Draw Bar Chart
If you havn't used cocoapods, please visit [http://cocoapods.org/] to learn the basic usage.
- step1. execute
pod init
in your command line and open your Podfile - step2. add
pod 'DBBarChart',:git=>'https://github.com/mengzhiqc/BarChart.git'
in your Podfile - step3. execute
pod install
-
import the header file
#import "DBBarChartView.h"
-
prepare the data to be displayed
eg.
NSArray *itemData = @[ @{@"itemName":@"Flower",@"value":@"5"}, @{@"itemName":@"Book",@"value":@"6"}, @{@"itemName":@"Bus",@"value":@"8"}, @{@"itemName":@"Others",@"value":@"2"}, ];
- init barChartView and set delegate to current view controller
DBBarChartView *barChartView = [[DBBarChartView alloc]initWithData:itemData frame:CGRectMake(0, 20, 280, 100)]; barChartView.delegate = self;
please don't forget to add BarChartViewDelegate
in your header file.
- add this view as subview
[self.view addSubview:barChartView];
- result as follow
- we have provided some delegate so that you can change color and some other properties of chart view
- (UIColor *)barColorOfChartView:(DBBarChartView *)barChartView ; - (UIColor *)labelColorOfChartView:(DBBarChartView *)barChartView ; - (UIColor *)numberLabelcolorOfChartView:(DBBarChartView *)barChartView ; - (CGFloat)widthOfBarCharView:(DBBarChartView *)charView;