LewBarChart - iOS 柱狀圖,支持多個 Y 軸

LewBarChart

iOS 柱狀圖,支持多個 Y 軸坐標

效果圖

效果圖

使用方法

_barChart = [[LewBarChart alloc]initWithFrame:CGRectMake(0, 145, SCREEN_WIDTH, 200)];

// 生成數據 NSMutableArray yVals1 = [[NSMutableArray alloc] init]; NSMutableArray yVals2 = [[NSMutableArray alloc] init];

double mult = 5 * 1000.f; for (int i = 0; i < 5; i++){ double val = (double) (arc4random_uniform(mult) + 3.0); [yVals1 addObject:@(val)];

val = (double) (arc4random_uniform(mult) + 3.0); [yVals2 addObject:@(val)]; }

LewBarChartDataSet set1 = [[LewBarChartDataSet alloc] initWithYValues:yVals1 label:@"報名人數"]; [set1 setBarColor:[UIColor colorWithRed:77.0 / 255.0 green:186.0 / 255.0 blue:122.0 / 255.0 alpha:1.0f]]; LewBarChartDataSet set2 = [[LewBarChartDataSet alloc] initWithYValues:yVals2 label:@"實到人數"]; [set2 setBarColor:[UIColor colorWithRed:245.0 / 255.0 green:94.0 / 255.0 blue:78.0 / 255.0 alpha:1.0f]];

NSMutableArray *dataSets = [[NSMutableArray alloc] init]; [dataSets addObject:set1]; [dataSets addObject:set2];

LewBarChartData *data = [[LewBarChartData alloc] initWithDataSets:dataSets]; data.xLabels = @[@"項目名稱1",@"項目名稱2",@"項目名稱3",@"項目名稱4",@"項目名稱5"]; data.itemSpace = 6;

// 設置柱狀圖 _barChart.data = data; _barChart.displayAnimated = YES; _barChart.chartMargin = UIEdgeInsetsMake(20, 15, 45, 15); _barChart.showYAxis = NO; _barChart.showNumber = YES; _barChart.legendView.alignment = LegendAlignmentHorizontal;

[self.view addSubview:_barChart]; [_barChart show];

// 設置圖例位置 CGPoint legendCenter = CGPointMake(SCREEN_WIDTH-_barChart.legendView.bounds.size.width/2, -18); _barChart.legendView.center = legendCenter;</pre>

License | 許可

This code is distributed under the terms of the MIT license.
代碼使用 MIT license 許可發布.

項目地址: https://github.com/pljhonglu/LewBarChart

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!