diff --git a/LifeLog/LifeLog/HistoryViewController.m b/LifeLog/LifeLog/HistoryViewController.m index 3988b43..a3e38f5 100644 --- a/LifeLog/LifeLog/HistoryViewController.m +++ b/LifeLog/LifeLog/HistoryViewController.m @@ -139,14 +139,55 @@ { set1 = (BarChartDataSet *)self.viewBarChart.data.dataSets[0]; set1.values = yVals; + + NSMutableArray *color = [[NSMutableArray alloc] init]; + for(int i = 0; i < yVals.count; i++) { + BarChartDataEntry *en = yVals[i]; + if(obj.step != 0) { + double percent = en.y / obj.step * 100; + if(percent > 80) { + [color addObject:[UIColor redColor]]; + } + else if(percent > 60) { + [color addObject:[UIColor yellowColor]]; + } + else { + [color addObject:[UIColor whiteColor]]; + } + } + else { + [color addObject:[UIColor whiteColor]]; + } + } + [set1 setColors:color]; + [self.viewBarChart.data notifyDataChanged]; [self.viewBarChart notifyDataSetChanged]; } else { set1 = [[BarChartDataSet alloc] initWithValues:yVals label:@""]; - [set1 setColor:[UIColor whiteColor]]; + NSMutableArray *color = [[NSMutableArray alloc] init]; + for(int i = 0; i < yVals.count; i++) { + BarChartDataEntry *en = yVals[i]; + if(obj.step != 0) { + double percent = en.y / obj.step * 100; + if(percent > 80) { + [color addObject:[UIColor redColor]]; + } + else if(percent > 60) { + [color addObject:[UIColor yellowColor]]; + } + else { + [color addObject:[UIColor whiteColor]]; + } + } + else { + [color addObject:[UIColor whiteColor]]; + } + } + [set1 setColors:color]; NSMutableArray *dataSets = [[NSMutableArray alloc] init]; [dataSets addObject:set1];