Merge branch 'independant-margins-bar-chart' of https://github.com/openhood/PNCh…
…art into openhood-independant-margins-bar-chart
Showing
3 changed files
with
87 additions
and
64 deletions
| @@ -52,7 +52,10 @@ typedef NSString *(^PNYLabelFormatter)(CGFloat yLabelValue); | @@ -52,7 +52,10 @@ typedef NSString *(^PNYLabelFormatter)(CGFloat yLabelValue); | ||
| 52 | /** Suffix to y label values, none if unset. */ | 52 | /** Suffix to y label values, none if unset. */ |
| 53 | @property (nonatomic) NSString *yLabelSuffix; | 53 | @property (nonatomic) NSString *yLabelSuffix; |
| 54 | 54 | ||
| 55 | -@property (nonatomic) CGFloat chartMargin; | 55 | +@property (nonatomic) CGFloat chartMarginLeft; |
| 56 | +@property (nonatomic) CGFloat chartMarginRight; | ||
| 57 | +@property (nonatomic) CGFloat chartMarginTop; | ||
| 58 | +@property (nonatomic) CGFloat chartMarginBottom; | ||
| 56 | 59 | ||
| 57 | /** Controls whether labels should be displayed. */ | 60 | /** Controls whether labels should be displayed. */ |
| 58 | @property (nonatomic) BOOL showLabel; | 61 | @property (nonatomic) BOOL showLabel; |
| @@ -24,7 +24,7 @@ | @@ -24,7 +24,7 @@ | ||
| 24 | - (id)initWithCoder:(NSCoder *)aDecoder | 24 | - (id)initWithCoder:(NSCoder *)aDecoder |
| 25 | { | 25 | { |
| 26 | self = [super initWithCoder:aDecoder]; | 26 | self = [super initWithCoder:aDecoder]; |
| 27 | - | 27 | + |
| 28 | if (self) { | 28 | if (self) { |
| 29 | [self setupDefaultValues]; | 29 | [self setupDefaultValues]; |
| 30 | } | 30 | } |
| @@ -56,7 +56,10 @@ | @@ -56,7 +56,10 @@ | ||
| 56 | _xLabelSkip = 1; | 56 | _xLabelSkip = 1; |
| 57 | _yLabelSum = 4; | 57 | _yLabelSum = 4; |
| 58 | _labelMarginTop = 0; | 58 | _labelMarginTop = 0; |
| 59 | - _chartMargin = 25.0; | 59 | + _chartMarginLeft = 25.0; |
| 60 | + _chartMarginRight = 25.0; | ||
| 61 | + _chartMarginTop = 25.0; | ||
| 62 | + _chartMarginBottom = 25.0; | ||
| 60 | _barRadius = 2.0; | 63 | _barRadius = 2.0; |
| 61 | _showChartBorder = NO; | 64 | _showChartBorder = NO; |
| 62 | _showLevelLine = NO; | 65 | _showLevelLine = NO; |
| @@ -75,7 +78,7 @@ | @@ -75,7 +78,7 @@ | ||
| 75 | { | 78 | { |
| 76 | _yValues = yValues; | 79 | _yValues = yValues; |
| 77 | //make the _yLabelSum value dependant of the distinct values of yValues to avoid duplicates on yAxis | 80 | //make the _yLabelSum value dependant of the distinct values of yValues to avoid duplicates on yAxis |
| 78 | - | 81 | + |
| 79 | if (_showLabel) { | 82 | if (_showLabel) { |
| 80 | [self __addYCoordinateLabelsValues]; | 83 | [self __addYCoordinateLabelsValues]; |
| 81 | } else { | 84 | } else { |
| @@ -91,7 +94,7 @@ | @@ -91,7 +94,7 @@ | ||
| 91 | } else { | 94 | } else { |
| 92 | [self getYValueMax:yAxisValues]; | 95 | [self getYValueMax:yAxisValues]; |
| 93 | } | 96 | } |
| 94 | - | 97 | + |
| 95 | if (_yLabelSum==4) { | 98 | if (_yLabelSum==4) { |
| 96 | _yLabelSum = yAxisValues.count; | 99 | _yLabelSum = yAxisValues.count; |
| 97 | (_yLabelSum % 2 == 0) ? _yLabelSum : _yLabelSum++; | 100 | (_yLabelSum % 2 == 0) ? _yLabelSum : _yLabelSum++; |
| @@ -101,12 +104,13 @@ | @@ -101,12 +104,13 @@ | ||
| 101 | #pragma mark - Private Method | 104 | #pragma mark - Private Method |
| 102 | #pragma mark - Add Y Label | 105 | #pragma mark - Add Y Label |
| 103 | - (void)__addYCoordinateLabelsValues{ | 106 | - (void)__addYCoordinateLabelsValues{ |
| 104 | - | 107 | + |
| 105 | [self viewCleanupForCollection:_yChartLabels]; | 108 | [self viewCleanupForCollection:_yChartLabels]; |
| 106 | - | 109 | + |
| 107 | [self processYMaxValue]; | 110 | [self processYMaxValue]; |
| 108 | - | 111 | + |
| 109 | - float sectionHeight = (self.frame.size.height - _chartMargin * 2 - kXLabelHeight) / _yLabelSum; | 112 | + float sectionHeight = (self.frame.size.height - _chartMarginTop - _chartMarginBottom - kXLabelHeight) / _yLabelSum; |
| 113 | + | ||
| 110 | for (int i = 0; i <= _yLabelSum; i++) { | 114 | for (int i = 0; i <= _yLabelSum; i++) { |
| 111 | NSString *labelText; | 115 | NSString *labelText; |
| 112 | if (_yLabels) { | 116 | if (_yLabels) { |
| @@ -115,15 +119,17 @@ | @@ -115,15 +119,17 @@ | ||
| 115 | } else { | 119 | } else { |
| 116 | labelText = _yLabelFormatter((float)_yValueMax * ( (_yLabelSum - i) / (float)_yLabelSum )); | 120 | labelText = _yLabelFormatter((float)_yValueMax * ( (_yLabelSum - i) / (float)_yLabelSum )); |
| 117 | } | 121 | } |
| 118 | - | 122 | + |
| 119 | - CGRect frame = (CGRect){0, sectionHeight * i + _chartMargin - kYLabelHeight/2.0, _yChartLabelWidth, kYLabelHeight}; | 123 | + PNChartLabel *label = [[PNChartLabel alloc] initWithFrame:CGRectZero]; |
| 120 | - PNChartLabel *label = [[PNChartLabel alloc] initWithFrame:frame]; | ||
| 121 | label.font = _labelFont; | 124 | label.font = _labelFont; |
| 122 | label.textColor = _labelTextColor; | 125 | label.textColor = _labelTextColor; |
| 123 | [label setTextAlignment:NSTextAlignmentRight]; | 126 | [label setTextAlignment:NSTextAlignmentRight]; |
| 124 | label.text = [NSString stringWithFormat:@"%@%@%@", _yLabelPrefix, labelText, _yLabelSuffix]; | 127 | label.text = [NSString stringWithFormat:@"%@%@%@", _yLabelPrefix, labelText, _yLabelSuffix]; |
| 128 | + | ||
| 125 | [self addSubview:label]; | 129 | [self addSubview:label]; |
| 126 | - | 130 | + |
| 131 | + label.frame = (CGRect){0, sectionHeight * i + _chartMarginTop - kYLabelHeight/2.0, _yChartLabelWidth, kYLabelHeight}; | ||
| 132 | + | ||
| 127 | [_yChartLabels addObject:label]; | 133 | [_yChartLabels addObject:label]; |
| 128 | } | 134 | } |
| 129 | } | 135 | } |
| @@ -148,20 +154,20 @@ | @@ -148,20 +154,20 @@ | ||
| 148 | - (void)setXLabels:(NSArray *)xLabels | 154 | - (void)setXLabels:(NSArray *)xLabels |
| 149 | { | 155 | { |
| 150 | _xLabels = xLabels; | 156 | _xLabels = xLabels; |
| 151 | - | 157 | + |
| 152 | if (_xChartLabels) { | 158 | if (_xChartLabels) { |
| 153 | [self viewCleanupForCollection:_xChartLabels]; | 159 | [self viewCleanupForCollection:_xChartLabels]; |
| 154 | }else{ | 160 | }else{ |
| 155 | _xChartLabels = [NSMutableArray new]; | 161 | _xChartLabels = [NSMutableArray new]; |
| 156 | } | 162 | } |
| 157 | - | 163 | + |
| 158 | - _xLabelWidth = (self.frame.size.width - _chartMargin * 2) / [xLabels count]; | 164 | + _xLabelWidth = (self.frame.size.width - _chartMarginLeft - _chartMarginRight) / [xLabels count]; |
| 159 | - | 165 | + |
| 160 | - if (_showLabel) { | 166 | + if (_showLabel) { |
| 161 | int labelAddCount = 0; | 167 | int labelAddCount = 0; |
| 162 | for (int index = 0; index < _xLabels.count; index++) { | 168 | for (int index = 0; index < _xLabels.count; index++) { |
| 163 | labelAddCount += 1; | 169 | labelAddCount += 1; |
| 164 | - | 170 | + |
| 165 | if (labelAddCount == _xLabelSkip) { | 171 | if (labelAddCount == _xLabelSkip) { |
| 166 | NSString *labelText = [_xLabels[index] description]; | 172 | NSString *labelText = [_xLabels[index] description]; |
| 167 | PNChartLabel * label = [[PNChartLabel alloc] initWithFrame:CGRectMake(0, 0, _xLabelWidth, kXLabelHeight)]; | 173 | PNChartLabel * label = [[PNChartLabel alloc] initWithFrame:CGRectMake(0, 0, _xLabelWidth, kXLabelHeight)]; |
| @@ -173,15 +179,15 @@ | @@ -173,15 +179,15 @@ | ||
| 173 | CGFloat labelXPosition; | 179 | CGFloat labelXPosition; |
| 174 | if (_rotateForXAxisText){ | 180 | if (_rotateForXAxisText){ |
| 175 | label.transform = CGAffineTransformMakeRotation(M_PI / 4); | 181 | label.transform = CGAffineTransformMakeRotation(M_PI / 4); |
| 176 | - labelXPosition = (index * _xLabelWidth + _chartMargin + _xLabelWidth /1.5); | 182 | + labelXPosition = (index * _xLabelWidth + _chartMarginLeft + _xLabelWidth /1.5); |
| 177 | } | 183 | } |
| 178 | else{ | 184 | else{ |
| 179 | - labelXPosition = (index * _xLabelWidth + _chartMargin + _xLabelWidth /2.0 ); | 185 | + labelXPosition = (index * _xLabelWidth + _chartMarginLeft + _xLabelWidth /2.0 ); |
| 180 | } | 186 | } |
| 181 | label.center = CGPointMake(labelXPosition, | 187 | label.center = CGPointMake(labelXPosition, |
| 182 | - self.frame.size.height - kXLabelHeight - _chartMargin + label.frame.size.height /2.0 + _labelMarginTop); | 188 | + self.frame.size.height - kXLabelHeight - _chartMarginTop + label.frame.size.height /2.0 + _labelMarginTop); |
| 183 | labelAddCount = 0; | 189 | labelAddCount = 0; |
| 184 | - | 190 | + |
| 185 | [_xChartLabels addObject:label]; | 191 | [_xChartLabels addObject:label]; |
| 186 | [self addSubview:label]; | 192 | [self addSubview:label]; |
| 187 | } | 193 | } |
| @@ -197,44 +203,44 @@ | @@ -197,44 +203,44 @@ | ||
| 197 | 203 | ||
| 198 | - (void)updateBar | 204 | - (void)updateBar |
| 199 | { | 205 | { |
| 200 | - | 206 | + |
| 201 | //Add bars | 207 | //Add bars |
| 202 | - CGFloat chartCavanHeight = self.frame.size.height - _chartMargin * 2 - kXLabelHeight; | 208 | + CGFloat chartCavanHeight = self.frame.size.height - _chartMarginTop - _chartMarginBottom - kXLabelHeight; |
| 203 | NSInteger index = 0; | 209 | NSInteger index = 0; |
| 204 | - | 210 | + |
| 205 | for (NSNumber *valueString in _yValues) { | 211 | for (NSNumber *valueString in _yValues) { |
| 206 | - | 212 | + |
| 207 | PNBar *bar; | 213 | PNBar *bar; |
| 208 | - | 214 | + |
| 209 | if (_bars.count == _yValues.count) { | 215 | if (_bars.count == _yValues.count) { |
| 210 | bar = [_bars objectAtIndex:index]; | 216 | bar = [_bars objectAtIndex:index]; |
| 211 | }else{ | 217 | }else{ |
| 212 | CGFloat barWidth; | 218 | CGFloat barWidth; |
| 213 | CGFloat barXPosition; | 219 | CGFloat barXPosition; |
| 214 | - | 220 | + |
| 215 | if (_barWidth) { | 221 | if (_barWidth) { |
| 216 | barWidth = _barWidth; | 222 | barWidth = _barWidth; |
| 217 | - barXPosition = index * _xLabelWidth + _chartMargin + _xLabelWidth /2.0 - _barWidth /2.0; | 223 | + barXPosition = index * _xLabelWidth + _chartMarginLeft + _xLabelWidth /2.0 - _barWidth /2.0; |
| 218 | }else{ | 224 | }else{ |
| 219 | - barXPosition = index * _xLabelWidth + _chartMargin + _xLabelWidth * 0.25; | 225 | + barXPosition = index * _xLabelWidth + _chartMarginLeft + _xLabelWidth * 0.25; |
| 220 | if (_showLabel) { | 226 | if (_showLabel) { |
| 221 | barWidth = _xLabelWidth * 0.5; | 227 | barWidth = _xLabelWidth * 0.5; |
| 222 | - | 228 | + |
| 223 | } | 229 | } |
| 224 | else { | 230 | else { |
| 225 | barWidth = _xLabelWidth * 0.6; | 231 | barWidth = _xLabelWidth * 0.6; |
| 226 | - | 232 | + |
| 227 | } | 233 | } |
| 228 | } | 234 | } |
| 229 | - | 235 | + |
| 230 | bar = [[PNBar alloc] initWithFrame:CGRectMake(barXPosition, //Bar X position | 236 | bar = [[PNBar alloc] initWithFrame:CGRectMake(barXPosition, //Bar X position |
| 231 | - self.frame.size.height - chartCavanHeight - kXLabelHeight - _chartMargin , //Bar Y position | 237 | + self.frame.size.height - chartCavanHeight - kXLabelHeight - _chartMarginTop , //Bar Y position |
| 232 | barWidth, // Bar witdh | 238 | barWidth, // Bar witdh |
| 233 | self.showLevelLine ? chartCavanHeight/2.0:chartCavanHeight)]; //Bar height | 239 | self.showLevelLine ? chartCavanHeight/2.0:chartCavanHeight)]; //Bar height |
| 234 | - | 240 | + |
| 235 | //Change Bar Radius | 241 | //Change Bar Radius |
| 236 | bar.barRadius = _barRadius; | 242 | bar.barRadius = _barRadius; |
| 237 | - | 243 | + |
| 238 | //Change Bar Background color | 244 | //Change Bar Background color |
| 239 | bar.backgroundColor = _barBackgroundColor; | 245 | bar.backgroundColor = _barBackgroundColor; |
| 240 | //Bar StrokColor First | 246 | //Bar StrokColor First |
| @@ -243,23 +249,23 @@ | @@ -243,23 +249,23 @@ | ||
| 243 | }else{ | 249 | }else{ |
| 244 | bar.barColor = [self barColorAtIndex:index]; | 250 | bar.barColor = [self barColorAtIndex:index]; |
| 245 | } | 251 | } |
| 246 | - | 252 | + |
| 247 | // Add gradient | 253 | // Add gradient |
| 248 | if (self.isGradientShow) { | 254 | if (self.isGradientShow) { |
| 249 | bar.barColorGradientStart = bar.barColor; | 255 | bar.barColorGradientStart = bar.barColor; |
| 250 | } | 256 | } |
| 251 | - | 257 | + |
| 252 | //For Click Index | 258 | //For Click Index |
| 253 | bar.tag = index; | 259 | bar.tag = index; |
| 254 | - | 260 | + |
| 255 | [_bars addObject:bar]; | 261 | [_bars addObject:bar]; |
| 256 | [self addSubview:bar]; | 262 | [self addSubview:bar]; |
| 257 | } | 263 | } |
| 258 | - | 264 | + |
| 259 | //Height Of Bar | 265 | //Height Of Bar |
| 260 | float value = [valueString floatValue]; | 266 | float value = [valueString floatValue]; |
| 261 | float grade =fabsf((float)value / (float)_yValueMax); | 267 | float grade =fabsf((float)value / (float)_yValueMax); |
| 262 | - | 268 | + |
| 263 | if (isnan(grade)) { | 269 | if (isnan(grade)) { |
| 264 | grade = 0; | 270 | grade = 0; |
| 265 | } | 271 | } |
| @@ -268,14 +274,14 @@ | @@ -268,14 +274,14 @@ | ||
| 268 | bar.isShowNumber = self.isShowNumbers; | 274 | bar.isShowNumber = self.isShowNumbers; |
| 269 | CGRect originalFrame = bar.frame; | 275 | CGRect originalFrame = bar.frame; |
| 270 | NSString *currentNumber = [NSString stringWithFormat:@"%f",value]; | 276 | NSString *currentNumber = [NSString stringWithFormat:@"%f",value]; |
| 271 | - | 277 | + |
| 272 | if ([[currentNumber substringToIndex:1] isEqualToString:@"-"] && self.showLevelLine) { | 278 | if ([[currentNumber substringToIndex:1] isEqualToString:@"-"] && self.showLevelLine) { |
| 273 | CGAffineTransform transform =CGAffineTransformMakeRotation(M_PI); | 279 | CGAffineTransform transform =CGAffineTransformMakeRotation(M_PI); |
| 274 | [bar setTransform:transform]; | 280 | [bar setTransform:transform]; |
| 275 | originalFrame.origin.y = bar.frame.origin.y + bar.frame.size.height; | 281 | originalFrame.origin.y = bar.frame.origin.y + bar.frame.size.height; |
| 276 | bar.frame = originalFrame; | 282 | bar.frame = originalFrame; |
| 277 | bar.isNegative = YES; | 283 | bar.isNegative = YES; |
| 278 | - | 284 | + |
| 279 | } | 285 | } |
| 280 | index += 1; | 286 | index += 1; |
| 281 | } | 287 | } |
| @@ -289,9 +295,9 @@ | @@ -289,9 +295,9 @@ | ||
| 289 | 295 | ||
| 290 | 296 | ||
| 291 | //Update Bar | 297 | //Update Bar |
| 292 | - | 298 | + |
| 293 | [self updateBar]; | 299 | [self updateBar]; |
| 294 | - | 300 | + |
| 295 | //Add chart border lines | 301 | //Add chart border lines |
| 296 | 302 | ||
| 297 | if (_showChartBorder) { | 303 | if (_showChartBorder) { |
| @@ -303,8 +309,8 @@ | @@ -303,8 +309,8 @@ | ||
| 303 | 309 | ||
| 304 | UIBezierPath *progressline = [UIBezierPath bezierPath]; | 310 | UIBezierPath *progressline = [UIBezierPath bezierPath]; |
| 305 | 311 | ||
| 306 | - [progressline moveToPoint:CGPointMake(_chartMargin, self.frame.size.height - kXLabelHeight - _chartMargin)]; | 312 | + [progressline moveToPoint:CGPointMake(_chartMarginLeft, self.frame.size.height - kXLabelHeight - _chartMarginTop)]; |
| 307 | - [progressline addLineToPoint:CGPointMake(self.frame.size.width - _chartMargin, self.frame.size.height - kXLabelHeight - _chartMargin)]; | 313 | + [progressline addLineToPoint:CGPointMake(self.frame.size.width - _chartMarginRight, self.frame.size.height - kXLabelHeight - _chartMarginTop)]; |
| 308 | 314 | ||
| 309 | [progressline setLineWidth:1.0]; | 315 | [progressline setLineWidth:1.0]; |
| 310 | [progressline setLineCapStyle:kCGLineCapSquare]; | 316 | [progressline setLineCapStyle:kCGLineCapSquare]; |
| @@ -321,7 +327,7 @@ | @@ -321,7 +327,7 @@ | ||
| 321 | _chartBottomLine.strokeEnd = 1.0; | 327 | _chartBottomLine.strokeEnd = 1.0; |
| 322 | 328 | ||
| 323 | [self.layer addSublayer:_chartBottomLine]; | 329 | [self.layer addSublayer:_chartBottomLine]; |
| 324 | - | 330 | + |
| 325 | //Add left Chart Line | 331 | //Add left Chart Line |
| 326 | 332 | ||
| 327 | _chartLeftLine = [CAShapeLayer layer]; | 333 | _chartLeftLine = [CAShapeLayer layer]; |
| @@ -332,8 +338,8 @@ | @@ -332,8 +338,8 @@ | ||
| 332 | 338 | ||
| 333 | UIBezierPath *progressLeftline = [UIBezierPath bezierPath]; | 339 | UIBezierPath *progressLeftline = [UIBezierPath bezierPath]; |
| 334 | 340 | ||
| 335 | - [progressLeftline moveToPoint:CGPointMake(_chartMargin, self.frame.size.height - kXLabelHeight - _chartMargin)]; | 341 | + [progressLeftline moveToPoint:CGPointMake(_chartMarginLeft, self.frame.size.height - kXLabelHeight - _chartMarginBottom + _chartMarginTop)]; |
| 336 | - [progressLeftline addLineToPoint:CGPointMake(_chartMargin, _chartMargin)]; | 342 | + [progressLeftline addLineToPoint:CGPointMake(_chartMarginLeft, _chartMarginTop)]; |
| 337 | 343 | ||
| 338 | [progressLeftline setLineWidth:1.0]; | 344 | [progressLeftline setLineWidth:1.0]; |
| 339 | [progressLeftline setLineCapStyle:kCGLineCapSquare]; | 345 | [progressLeftline setLineCapStyle:kCGLineCapSquare]; |
| @@ -351,7 +357,7 @@ | @@ -351,7 +357,7 @@ | ||
| 351 | 357 | ||
| 352 | [self.layer addSublayer:_chartLeftLine]; | 358 | [self.layer addSublayer:_chartLeftLine]; |
| 353 | } | 359 | } |
| 354 | - | 360 | + |
| 355 | // Add Level Separator Line | 361 | // Add Level Separator Line |
| 356 | if (_showLevelLine) { | 362 | if (_showLevelLine) { |
| 357 | _chartLevelLine = [CAShapeLayer layer]; | 363 | _chartLevelLine = [CAShapeLayer layer]; |
| @@ -359,27 +365,27 @@ | @@ -359,27 +365,27 @@ | ||
| 359 | _chartLevelLine.fillColor = [[UIColor whiteColor] CGColor]; | 365 | _chartLevelLine.fillColor = [[UIColor whiteColor] CGColor]; |
| 360 | _chartLevelLine.lineWidth = 1.0; | 366 | _chartLevelLine.lineWidth = 1.0; |
| 361 | _chartLevelLine.strokeEnd = 0.0; | 367 | _chartLevelLine.strokeEnd = 0.0; |
| 362 | - | 368 | + |
| 363 | UIBezierPath *progressline = [UIBezierPath bezierPath]; | 369 | UIBezierPath *progressline = [UIBezierPath bezierPath]; |
| 364 | - | 370 | + |
| 365 | - [progressline moveToPoint:CGPointMake(_chartMargin, (self.frame.size.height - kXLabelHeight )/2.0)]; | 371 | + [progressline moveToPoint:CGPointMake(_chartMarginLeft, (self.frame.size.height - kXLabelHeight )/2.0)]; |
| 366 | - [progressline addLineToPoint:CGPointMake(self.frame.size.width - _chartMargin, (self.frame.size.height - kXLabelHeight )/2.0)]; | 372 | + [progressline addLineToPoint:CGPointMake(self.frame.size.width - _chartMarginLeft - _chartMarginRight, (self.frame.size.height - kXLabelHeight )/2.0)]; |
| 367 | - | 373 | + |
| 368 | [progressline setLineWidth:1.0]; | 374 | [progressline setLineWidth:1.0]; |
| 369 | [progressline setLineCapStyle:kCGLineCapSquare]; | 375 | [progressline setLineCapStyle:kCGLineCapSquare]; |
| 370 | _chartLevelLine.path = progressline.CGPath; | 376 | _chartLevelLine.path = progressline.CGPath; |
| 371 | - | 377 | + |
| 372 | _chartLevelLine.strokeColor = PNLightGrey.CGColor; | 378 | _chartLevelLine.strokeColor = PNLightGrey.CGColor; |
| 373 | - | 379 | + |
| 374 | CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"]; | 380 | CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"]; |
| 375 | pathAnimation.duration = 0.5; | 381 | pathAnimation.duration = 0.5; |
| 376 | pathAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; | 382 | pathAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; |
| 377 | pathAnimation.fromValue = @0.0f; | 383 | pathAnimation.fromValue = @0.0f; |
| 378 | pathAnimation.toValue = @1.0f; | 384 | pathAnimation.toValue = @1.0f; |
| 379 | [_chartLevelLine addAnimation:pathAnimation forKey:@"strokeEndAnimation"]; | 385 | [_chartLevelLine addAnimation:pathAnimation forKey:@"strokeEndAnimation"]; |
| 380 | - | 386 | + |
| 381 | _chartLevelLine.strokeEnd = 1.0; | 387 | _chartLevelLine.strokeEnd = 1.0; |
| 382 | - | 388 | + |
| 383 | [self.layer addSublayer:_chartLevelLine]; | 389 | [self.layer addSublayer:_chartLevelLine]; |
| 384 | } else { | 390 | } else { |
| 385 | if (_chartLevelLine) { | 391 | if (_chartLevelLine) { |
| @@ -91,20 +91,34 @@ | @@ -91,20 +91,34 @@ | ||
| 91 | } | 91 | } |
| 92 | else if ([self.title isEqualToString:@"Bar Chart"]) | 92 | else if ([self.title isEqualToString:@"Bar Chart"]) |
| 93 | { | 93 | { |
| 94 | + static NSNumberFormatter *barChartFormatter; | ||
| 95 | + if (!barChartFormatter){ | ||
| 96 | + barChartFormatter = [[NSNumberFormatter alloc] init]; | ||
| 97 | + barChartFormatter.numberStyle = NSNumberFormatterCurrencyStyle; | ||
| 98 | + barChartFormatter.allowsFloats = NO; | ||
| 99 | + barChartFormatter.maximumFractionDigits = 0; | ||
| 100 | + } | ||
| 94 | self.titleLabel.text = @"Bar Chart"; | 101 | self.titleLabel.text = @"Bar Chart"; |
| 95 | 102 | ||
| 96 | self.barChart = [[PNBarChart alloc] initWithFrame:CGRectMake(0, 135.0, SCREEN_WIDTH, 200.0)]; | 103 | self.barChart = [[PNBarChart alloc] initWithFrame:CGRectMake(0, 135.0, SCREEN_WIDTH, 200.0)]; |
| 97 | // self.barChart.showLabel = NO; | 104 | // self.barChart.showLabel = NO; |
| 98 | self.barChart.backgroundColor = [UIColor clearColor]; | 105 | self.barChart.backgroundColor = [UIColor clearColor]; |
| 99 | self.barChart.yLabelFormatter = ^(CGFloat yValue){ | 106 | self.barChart.yLabelFormatter = ^(CGFloat yValue){ |
| 100 | - CGFloat yValueParsed = yValue; | 107 | + return [barChartFormatter stringFromNumber:[NSNumber numberWithFloat:yValue]]; |
| 101 | - NSString * labelText = [NSString stringWithFormat:@"%0.f",yValueParsed]; | ||
| 102 | - return labelText; | ||
| 103 | }; | 108 | }; |
| 109 | + | ||
| 110 | + self.barChart.yChartLabelWidth = 20.0; | ||
| 111 | + self.barChart.chartMarginLeft = 30.0; | ||
| 112 | + self.barChart.chartMarginRight = 10.0; | ||
| 113 | + self.barChart.chartMarginTop = 5.0; | ||
| 114 | + self.barChart.chartMarginBottom = 10.0; | ||
| 115 | + | ||
| 116 | + | ||
| 104 | self.barChart.labelMarginTop = 5.0; | 117 | self.barChart.labelMarginTop = 5.0; |
| 105 | self.barChart.showChartBorder = YES; | 118 | self.barChart.showChartBorder = YES; |
| 106 | [self.barChart setXLabels:@[@"2",@"3",@"4",@"5",@"2",@"3",@"4",@"5"]]; | 119 | [self.barChart setXLabels:@[@"2",@"3",@"4",@"5",@"2",@"3",@"4",@"5"]]; |
| 107 | // self.barChart.yLabels = @[@-10,@0,@10]; | 120 | // self.barChart.yLabels = @[@-10,@0,@10]; |
| 121 | +// [self.barChart setYValues:@[@10000.0,@30000.0,@10000.0,@100000.0,@500000.0,@1000000.0,@1150000.0,@2150000.0]]; | ||
| 108 | [self.barChart setYValues:@[@10.82,@1.88,@6.96,@33.93,@10.82,@1.88,@6.96,@33.93]]; | 122 | [self.barChart setYValues:@[@10.82,@1.88,@6.96,@33.93,@10.82,@1.88,@6.96,@33.93]]; |
| 109 | [self.barChart setStrokeColors:@[PNGreen,PNGreen,PNRed,PNGreen,PNGreen,PNGreen,PNRed,PNGreen]]; | 123 | [self.barChart setStrokeColors:@[PNGreen,PNGreen,PNRed,PNGreen,PNGreen,PNGreen,PNRed,PNGreen]]; |
| 110 | self.barChart.isGradientShow = NO; | 124 | self.barChart.isGradientShow = NO; |
-
Please register or login to post a comment