ios 图表 - LCChartView

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

line.gif

bar.gif

pie.gif

arc.gif

用法:

/* 每种图形样式都支持颜色,文字的自定义设置,修复对应的属性即可 */
// 数据
    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];
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容