导入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 {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSString *jsFilePath = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"js"];
_chartView = [[TWRChartView alloc]initWithFrame:CGRectMake(0, 104,[[UIScreen mainScreen] bounds].size.width, 276)];
[_chartView setChartJsFilePath:jsFilePath];
_chartView.backgroundColor = [UIColor whiteColor];
[self.view addSubview:_chartView];
[self loadBarChart];
}
-(void)loadBarChart
{
NSArray *array1 = @[@"121", @"11", @"8"];
NSArray *array2 = @[@"44", @"31", @"22"];
NSArray *array3 = @[@"8", @"32", @"55"];
TWRDataSet *dataSet1 = [[TWRDataSet alloc] initWithDataPoints:array2
fillColor:[HEXCOLOR(0xf13c3d) colorWithAlphaComponent:0.5]
strokeColor:[UIColor clearColor]];
TWRDataSet *dataSet2 = [[TWRDataSet alloc] initWithDataPoints:array1
fillColor:[HEXCOLOR(0xffb633) colorWithAlphaComponent:0.5]
strokeColor:[UIColor clearColor]];
// NSArray *labels = @[@"A", @"B", @"C", @"D", @"E",@"F"];
TWRBarChart *bar = [[TWRBarChart alloc] initWithLabels:array3
dataSets:@[dataSet1,dataSet2]
animated:YES];
// Load data
[_chartView loadBarChart:bar withCompletionHandler:^(BOOL finished) {
}];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end