iOS实现折线图、柱状图、圆饼图

来源:互联网 发布:linux 虚机网络不通 编辑:程序博客网 时间:2024/05/16 01:20

最近项目中用到一些图表展示数据,闲下来封装了一下,支持折线图、柱状图、 饼状图、环形图,其中折线图、柱状图支持tap手势缩放、pan手势缩放。代码地址:https://github.com/Rochang/LCChartView。
使用方法:

/* 每种图形样式都支持颜色,文字的自定义设置,修复对应的属性即可 */// 数据    LCChartViewModel *model0 = [LCChartViewModel modelWithColor:RandomColor plots:[self randomArrayWithCount:12] project:@"1组"];    LCChartViewModel *model1 = [LCChartViewModel modelWithColor:RandomColor plots:[self randomArrayWithCount:12] project:@"2组"];    LCChartViewModel *model2 = [LCChartViewModel modelWithColor:RandomColor plots:[self randomArrayWithCount:12] project:@"3组"];    LCChartViewModel *model3 = [LCChartViewModel modelWithColor:RandomColor plots:[self randomArrayWithCount:12] project:@"4组"];    LCChartViewModel *model4 = [LCChartViewModel modelWithColor:RandomColor plots:[self randomArrayWithCount:12] project:@"5组"];// 折线图  LCChartView *chartViewLine = [LCChartView chartViewWithType:LCChartViewTypeLine];  chartViewLine.frame = CGRectMake(0, 64, self.view.LC_width, 250);  [self.chartViewLine showChartViewWithYAxisMaxValue:1000 dataSource:@[model0, model1]];// 柱状图  LCChartView *chartViewLine = [LCChartView chartViewWithType:LCChartViewTypeBar];  chartViewLine.frame = CGRectMake(0, 64, self.view.LC_width, 250);  [self.chartViewLine showChartViewWithYAxisMaxValue:1000 dataSource:@[model, model1, model2, model3, model4]];// 饼状图  LCPieViewModel *modelP0 = [LCPieViewModel modelWithValue:arc4random_uniform(100) color:[UIColor redColor] text:@"1组"];  LCPieViewModel *modelP1 = [LCPieViewModel modelWithValue:arc4random_uniform(100) color:[UIColor grayColor] text:@"2组"];  LCPieViewModel *modelP2 = [LCPieViewModel modelWithValue:arc4random_uniform(100) color:[UIColor blueColor] text:@"3组"];  LCPieView *pieView = [LCPieView pieView];  pieView.frame = CGRectMake(0, 650, self.view.LC_width, 200);  [pieView showPieViewWithDataSource:@[modelP0, modelP1, modelP2]];// 环形图LCArcView *arcView = [[LCArcView alloc] initWithFrame:CGRectMake(0, 900, self.view.LC_width, 150)];[arcView showArcViewWithBgStartAngle:0 endBgAngle:M_PI * 2 bgAnimation:NO StartAngle:0 endAngle:M_PI animaion:YES];

折线图

柱状图

圆饼图

圆环图

原创粉丝点击