[Code Note] bar chart, note column chart
I ,.
2. Engineering Drawing.
3. Code.
RootViewController. h
#import <UIKit/UIKit.h>@interface RootViewController : UIViewController{ UIView* zhuView;}@end
RootViewController. m
# Import "RootViewController. h "@ interface RootViewController () @ end @ implementation RootViewController-(id) initWithNibName :( NSString *) bundle :( NSBundle *) handle {self = [super initWithNibName: nibNameOrNil bundle: nibBundleOrNil]; if (self) {// Custom initialization} return self;}-(void) viewDidLoad {[super viewDidLoad]; // Do any additional setup after loading the view. self. title = @ "Bar Chart"; self. view. backgroundColor = [UIColor greenColor]; [self initZhuView: [NSArray arrayWithObjects: @ "10", @ "20", @ "30", @ "40", @ "50 ", @ "60", @ "70", @ "80", @ "90", nil];} # pragma-mark-histogram initialization-(void) initZhuView :( NSArray *) days {if ([UIScreen mainScreen] bounds]. size. height> 480) {zhuView = [[UIView alloc] initWithFrame: CGRectMake (0,310-45 + 50,320,150)];} else {zhuView = [[UIView alloc] initWithFrame: CGRectMake (0,310-45,320,150)];} // background image where the bar chart is located [self. view addSubview: zhuView]; // 0 days, 50 days, 100 days of the vertical line UIView * shuView = [[UIView alloc] initWithFrame: CGRectMake (55, 0, 1,120)]; [shuView setBackgroundColor: [UIColor orangeColor]; [zhuView addSubview: shuView]; // UIView * hengView = [[UIView alloc] initWithFrame: CGRectMake (shuView. frame), CGRectGetMaxY (shuView. frame), 320-CGRectGetMinX (shuView. frame)-20, 1)]; [hengView setBackgroundColor: [UIColor orangeColor]; [zhuView addSubview: hengView]; NSArray * titles = [NSArray arrayWithObjects: @ "100 days ", @ "50 days", @ "0 days", nil]; for (int I = 0; I <3; I ++) {// Label UILabel * yibaiLb = [[UILabel alloc] initWithFrame: CGRectMake (0, 5 + I * 50, 53, 15)]; [yibaiLb setText: [titles objectAtIndex: I]; [yibaiLb setTextAlignment: Custom]; [yibaiLb setFont: [UIFont systemFontOfSize: 14]; [yibaiLb setBackgroundColor: [UIColor clearColor]; [zhuView addSubview: yibaiLb] ;}for (int I = 0; I <[days count]; I ++) {int height = [[days objectAtIndex: I] intValue]; if (height> = 100) height = 100; // The bar chart of the red vertical bar, UIImageView * imageView = [[UIImageView alloc] initWithFrame: CGRectMake (CGRectGetMaxX (shuView. frame) + 10 + I * 25, CGRectGetMinY (hengView. frame)-height, 15, height)]; [imageView setBackgroundColor: [UIColor redColor]; [zhuView addSubview: imageView]; // The red number Label UILabel * dayLB = [[UILabel alloc] initWithFrame: CGRectMake (CGRectGetMinX (imageView. frame)-5, CGRectGetMinY (imageView. frame)-10, 25, 10)]; [dayLB setTextAlignment: NSTextAlignmentCenter]; [dayLB setBackgroundColor: [UIColor clearColor]; [dayLB setFont: [UIFont systemFontOfSize: 10]; [dayLB setText: [NSString stringWithFormat: @ "% d", [[days objectAtIndex: I] intValue]; [zhuView addSubview: dayLB]; // Label UILabel * diLb = [UILabel alloc] initWithFrame: CGRectMake (CGRectGetMinX (imageView. frame), CGRectGetMaxY (hengView. frame), 15, 20)]; [diLb setText: [NSString stringWithFormat: @ "% d", I + 1]; [diLb setBackgroundColor: [UIColor clearColor]; [diLb setTextAlignment: NSTextAlignmentCenter]; [diLb setFont: [UIFont systemFontOfSize: 14]; [zhuView addSubview: diLb];}