TWRCharts实现动画图表

来源:互联网 发布:请州长夫人演唱 知乎 编辑:程序博客网 时间:2024/04/30 08:47

导入TWRCharts

#import <UIKit/UIKit.h>


@interface ViewController : UIViewController


-(void)loadBarChart;


@end


#import "ViewController.h"

#import "TWRChart.h"


//16进制色值

#define HEXCOLOR(c) [UIColor colorWithRed:((c>>16)&0xFF)/255.0 green:((c>>8)&0xFF)/255.0 blue:(c&0xFF)/255.0 alpha:1.0]

@interface ViewController ()


@property(strong, nonatomic)TWRChartView *chartView;


@end


@implementation ViewController


- (void)viewDidLoad {

    [superviewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.

    NSString *jsFilePath = [[NSBundlemainBundle] pathForResource:@"index"ofType:@"js"];

    _chartView = [[TWRChartViewalloc]initWithFrame:CGRectMake(0,104,[[UIScreenmainScreen] bounds].size.width,276)];

    [_chartView setChartJsFilePath:jsFilePath];

    _chartView.backgroundColor = [UIColorwhiteColor];

    [self.viewaddSubview:_chartView];

    

    [selfloadBarChart];

}


-(void)loadBarChart

{

    NSArray *array1 = @[@"121", @"11", @"8"];

    NSArray *array2 = @[@"44", @"31", @"22"];

    NSArray *array3 = @[@"8", @"32", @"55"];

    TWRDataSet *dataSet1 = [[TWRDataSetalloc] initWithDataPoints:array2

                                                        fillColor:[HEXCOLOR(0xf13c3d)colorWithAlphaComponent:0.5]

                                                      strokeColor:[UIColor clearColor]];


    TWRDataSet *dataSet2 = [[TWRDataSetalloc] initWithDataPoints:array1

                                                        fillColor:[HEXCOLOR(0xffb633) colorWithAlphaComponent:0.5]

                                                      strokeColor:[UIColor clearColor]];


    //    NSArray *labels = @[@"A", @"B", @"C", @"D", @"E",@"F"];

    TWRBarChart *bar = [[TWRBarChartalloc] initWithLabels:array3

                                                  dataSets:@[dataSet1,dataSet2]

                                                  animated:YES];

    // Load data

    [_chartViewloadBarChart:bar withCompletionHandler:^(BOOL finished) {

        

    }];

}


- (void)didReceiveMemoryWarning {

    [superdidReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}



@end



原创粉丝点击