一、概念
- (void)viewDidLoad { [superviewDidLoad]; //初始化 SHPieChart *chart = [[SHPieChart alloc]initWithFrame:CGRectMake(0,40, SHSCREEN_WIDTH, SHSCREEN_HEIGHT /3.0f)]; chart.backgroundColor = [UIColor orangeColor]; [self.view addSubview:chart]; }
二、最基本的写法-也是最笨的方法
//常见方法
- (void)commonMethods{ //创建数据模块 SHChartPointItem *item1 = [SHChartPointItem chartPoinItemWithRawX:@"敲代码"andRowY:@"0.33"]; SHChartPointItem *item2 = [SHChartPointItem chartPoinItemWithRawX:@"调程序"andRowY:@"0.34"]; SHChartPointItem *item3 = [SHChartPointItem chartPoinItemWithRawX:@"吃饭费"andRowY:@"0.23"]; SHChartPointItem *item4 = [SHChartPointItem chartPoinItemWithRawX:@"其他"andRowY:@"0.1"]; pieChartData.items =@[item1,item2,item3,item4].mutableCopy; pieChartData.fillColors =@[[UIColor redColor],[UIColor blueColor],[UIColor cyanColor],[UIColor yellowColor]].mutableCopy; chart.pieChartData = pieChartData; [chart strokeChart]; }
三、推荐方法
//推荐方法
- (void)recommendedApproach{ NSArray*titleArray =@[@"0.33",@"0.34",@"0.23",@"0.1",@"0.33",@"0.34",@"0.23",@"0.1"]; NSMutableArray*itemArrayM = [NSMutableArrayarray]; SHPieChartData *pieChartData = [[SHPieChartData alloc]init]; for(inti =0; i < titleArray.count; i++) { SHChartPointItem *item = [SHChartPointItem chartPoinItemWithRawX:@""andRowY:titleArray[i]]; [itemArrayM addObject:item]; } pieChartData.items = itemArrayM.mutableCopy; chart.pieChartData = pieChartData; [chart strokeChart]; }
谢谢!!!