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)

图片描述


EscapedDog
192 声望24 粉丝

objcer