[iOS]RBChart - LineChart

介绍RBChart自定义图表控件的实现方法,包括如何配置线形图表、设置线条颜色、宽度及节点样式等。该控件适用于iOS平台。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

RBChart - 实现一种通过配置来自定义的图表控件

    RBLineChart *chart = [[RBLineChart alloc] initWithFrame:CGRectMake(0, 40, CGRectGetWidth([UIScreen mainScreen].bounds), 94)];
    chart.backgroundColor = [UIColor clearColor];

    RBLineData *data = [RBLineData new];
    data.values = @[@10, @80, @90, @78, @98, @79, @87];
    RBLineDecorator *lineDecorator = [[RBLineDecorator alloc] initWithHandler:^(RBLineDecorator *decorator) {
        decorator.lineColor = [UIColor colorWithRed:0.095 green:0.744 blue:0.911 alpha:1.000];
        decorator.pointWidth = 5;
        decorator.lineWidth = 2.;
        decorator.lineNode = [[RBLineSolidNode alloc] initWithHandler:^(RBLineSolidNode *node) {
            node.fillColor = [UIColor colorWithRed:0.095 green:0.744 blue:0.911 alpha:1.000];
            node.strokeColor = [UIColor colorWithRed:0.095 green:0.744 blue:0.911 alpha:1.000];
        }];
    }];
    data.lineDecorator = lineDecorator;

    RBLineData *data2 = [RBLineData new];
    data2.values = @[@20, @60, @40, @98, @70, @65, @30];
    RBLineDecorator *lineDecorator2 = [[RBLineDecorator alloc] initWithHandler:^(RBLineDecorator *decorator) {
        decorator.lineColor = [UIColor colorWithRed:0.911 green:0.902 blue:0.169 alpha:1.000];
        decorator.pointWidth = 5;
        decorator.lineWidth = 2.;
        decorator.lineNode = [[RBLineHollowNode alloc] initWithHandler:^(RBLineHollowNode *node) {
            node.lineWidth = 2;
            node.strokeColor = [UIColor colorWithRed:0.911 green:0.902 blue:0.169 alpha:1.000];
        }];
    }];
    data2.lineDecorator = lineDecorator2;

    [chart setDatas:@[data, data2] titles:@[@"摄入", @"消耗"]];

    chart.chartDecorator = [[RBLineChartDecorator alloc] initWithHandler:^(RBLineChartDecorator *decorator) {
        decorator.backgroundColor = [UIColor blackColor];
        decorator.leading = 20;
    }];

    chart.maxValue = 120;

    [chart handlerTouch:^(NSInteger index, NSArray *values) {
        NSLog(@"index %li values: %@", (long)index, values);
    }];
    [self.view addSubview:chart];
    [chart draw];

RBLineChart: 线形图表
RBLineData: 线的数据(数值与修饰器)
RBLineDecorator: 修饰一条线(颜色、粗细、节点)
RBLineNode: 节点(实现RBLineNodeProtocol)
RBLineChartDecorator: 图表的修饰器(背景、Leading)

图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值