? ? ? ? 之前有一個(gè)需求要求寫一個(gè)柱狀圖,扒了好多代碼沒有合適的,就從code4App上找了一個(gè)稍微有點(diǎn)相似的Demo進(jìn)行了一些修改(時(shí)間有點(diǎn)久,具體demo地址沒有找到),希望對大家有點(diǎn)幫助

簡單的調(diào)用代碼如下:
-(void)creatChart{
? ? JHColumnChart *column = [[JHColumnChart alloc] initWithFrame:CGRectMake(0, 100, [UIScreen mainScreen].bounds.size.width, 300)];
? ? column.backgroundColor = [UIColor redColor];
? ? column.valueArr=? @[
?? ? ? ? ? ? ? ? ? ? ? ? @[@10],
?? ? ? ? ? ? ? ? ? ? ? ? @[@20],
?? ? ? ? ? ? ? ? ? ? ? ? @[@8],
?? ? ? ? ? ? ? ? ? ? ? ? @[@50],
?? ? ? ? ? ? ? ? ? ? ? ? @[@22],
?? ? ? ? ? ? ? ? ? ? ? ? @[@34],
?? ? ? ? ? ? ? ? ? ? ? ? @[@9],
?? ? ? ? ? ? ? ? ? ? ? ? @[@22],
?? ? ? ? ? ? ? ? ? ? ? ? @[@34]
?? ? ? ? ? ? ? ? ? ? ? ? ];
? ? column.originSize=CGPointMake(30,30);
}
可設(shè)置的一些屬性:
//峰值
//@property (nonatomic,assign) CGFloat maxHeight1;
//柱狀圖數(shù)組的顏色
@property(nonatomic,strong)NSArray * columnBGcolorsArr;
//y軸的值
@property (nonatomic, strong) NSArray * valueArr;
//整個(gè)大柱狀圖的背景顏色
@property(nonatomic,strong)UIColor? * bgVewBackgoundColor;
//列間距,非連續(xù)的默認(rèn)是5
@property (nonatomic, assign) CGFloat typeSpace;
//圓柱寬度
@property (nonatomic, assign) CGFloat columnWidth;
//是否需要x軸y軸
@property (nonatomic, assign) BOOL needXandYLine;
//y軸虛線指導(dǎo)顏色
@property (nonatomic, strong) UIColor * dashColor;
//左下腳距離x,y的起點(diǎn)
@property (nonatomic, assign) CGPoint originSize;
//外面?zhèn)鬟^來的線的值,轉(zhuǎn)變成在屏幕的位置傳過來
@property (nonatomic, strong)NSArray *jingJieXianArr;
//盛放數(shù)據(jù)數(shù)組? 跟數(shù)據(jù)一對一? 放到另一個(gè)數(shù)組里
@property (nonatomic, strong)NSArray *isKongArr;
? ? //畫警戒線
? ? column.jingJieXianArr=@[@50,@20];
? ? //設(shè)置每個(gè)柱的寬度 默認(rèn)顯示8個(gè)
? ? column.columnWidth=20;
? ? column.typeSpace=20;
? ? column.bgVewBackgoundColor = [UIColor clearColor];
? ? //開始動(dòng)畫
? ? [columnshowAnimation];
? ? [self.viewaddSubview:column];
下面是demo地址,因?yàn)榘凑招枨髮懲曛髲捻?xiàng)目中摳出的一部分,所以有點(diǎn)亂,勿噴,哈哈。。。
鏈接:https://pan.quark.cn/s/6f6aabb6edaa