Commit 29486f50ff55914f3ba67a2fe8d5da65f3dd5036

Authored by nvtu11790@gmail.com
1 parent 5739e821e5

Set color for graph depend on percent of steps

Showing 1 changed file with 42 additions and 1 deletions Side-by-side Diff

LifeLog/LifeLog/HistoryViewController.m
... ... @@ -139,14 +139,55 @@
139 139 {
140 140 set1 = (BarChartDataSet *)self.viewBarChart.data.dataSets[0];
141 141 set1.values = yVals;
  142 +
  143 + NSMutableArray *color = [[NSMutableArray alloc] init];
  144 + for(int i = 0; i < yVals.count; i++) {
  145 + BarChartDataEntry *en = yVals[i];
  146 + if(obj.step != 0) {
  147 + double percent = en.y / obj.step * 100;
  148 + if(percent > 80) {
  149 + [color addObject:[UIColor redColor]];
  150 + }
  151 + else if(percent > 60) {
  152 + [color addObject:[UIColor yellowColor]];
  153 + }
  154 + else {
  155 + [color addObject:[UIColor whiteColor]];
  156 + }
  157 + }
  158 + else {
  159 + [color addObject:[UIColor whiteColor]];
  160 + }
  161 + }
  162 + [set1 setColors:color];
  163 +
142 164 [self.viewBarChart.data notifyDataChanged];
143 165 [self.viewBarChart notifyDataSetChanged];
144 166 }
145 167 else
146 168 {
147 169 set1 = [[BarChartDataSet alloc] initWithValues:yVals label:@""];
148   - [set1 setColor:[UIColor whiteColor]];
149 170  
  171 + NSMutableArray *color = [[NSMutableArray alloc] init];
  172 + for(int i = 0; i < yVals.count; i++) {
  173 + BarChartDataEntry *en = yVals[i];
  174 + if(obj.step != 0) {
  175 + double percent = en.y / obj.step * 100;
  176 + if(percent > 80) {
  177 + [color addObject:[UIColor redColor]];
  178 + }
  179 + else if(percent > 60) {
  180 + [color addObject:[UIColor yellowColor]];
  181 + }
  182 + else {
  183 + [color addObject:[UIColor whiteColor]];
  184 + }
  185 + }
  186 + else {
  187 + [color addObject:[UIColor whiteColor]];
  188 + }
  189 + }
  190 + [set1 setColors:color];
150 191 NSMutableArray *dataSets = [[NSMutableArray alloc] init];
151 192 [dataSets addObject:set1];
152 193