Showing
1 changed file
with
35 additions
and
9 deletions
| @@ -424,29 +424,55 @@ | @@ -424,29 +424,55 @@ | ||
| 424 | { | 424 | { |
| 425 | if (self.isShowCoordinateAxis) { | 425 | if (self.isShowCoordinateAxis) { |
| 426 | 426 | ||
| 427 | + CGFloat yAsixOffset = 10.f; | ||
| 428 | + | ||
| 427 | CGContextRef ctx = UIGraphicsGetCurrentContext(); | 429 | CGContextRef ctx = UIGraphicsGetCurrentContext(); |
| 428 | UIGraphicsPushContext(ctx); | 430 | UIGraphicsPushContext(ctx); |
| 429 | CGContextSetLineWidth(ctx, self.axisWidth); | 431 | CGContextSetLineWidth(ctx, self.axisWidth); |
| 430 | CGContextSetStrokeColorWithColor(ctx, [self.axisColor CGColor]); | 432 | CGContextSetStrokeColorWithColor(ctx, [self.axisColor CGColor]); |
| 431 | 433 | ||
| 434 | + CGFloat xAxisWidth = CGRectGetWidth(rect) - _chartMargin/2; | ||
| 435 | + CGFloat yAxisHeight = _chartMargin + _chartCavanHeight; | ||
| 436 | + | ||
| 432 | // draw coordinate axis | 437 | // draw coordinate axis |
| 433 | - CGContextMoveToPoint(ctx, _chartMargin + 10, 0); | 438 | + CGContextMoveToPoint(ctx, _chartMargin + yAsixOffset, 0); |
| 434 | - CGContextAddLineToPoint(ctx, _chartMargin + 10, _chartMargin + _chartCavanHeight); | 439 | + CGContextAddLineToPoint(ctx, _chartMargin + yAsixOffset, yAxisHeight); |
| 435 | - CGContextAddLineToPoint(ctx, CGRectGetWidth(rect) - _chartMargin, _chartMargin + _chartCavanHeight); | 440 | + CGContextAddLineToPoint(ctx, xAxisWidth, yAxisHeight); |
| 436 | CGContextStrokePath(ctx); | 441 | CGContextStrokePath(ctx); |
| 437 | 442 | ||
| 438 | // draw y axis arrow | 443 | // draw y axis arrow |
| 439 | - CGContextMoveToPoint(ctx, _chartMargin + 6, 8); | 444 | + CGContextMoveToPoint(ctx, _chartMargin + yAsixOffset - 3, 6); |
| 440 | - CGContextAddLineToPoint(ctx, _chartMargin + 10, 0); | 445 | + CGContextAddLineToPoint(ctx, _chartMargin + yAsixOffset, 0); |
| 441 | - CGContextAddLineToPoint(ctx, _chartMargin + 14, 8); | 446 | + CGContextAddLineToPoint(ctx, _chartMargin + yAsixOffset + 3, 6); |
| 442 | CGContextStrokePath(ctx); | 447 | CGContextStrokePath(ctx); |
| 443 | 448 | ||
| 444 | // draw x axis arrow | 449 | // draw x axis arrow |
| 445 | - CGContextMoveToPoint(ctx, CGRectGetWidth(rect) - _chartMargin - 8, _chartMargin + _chartCavanHeight - 4); | 450 | + CGContextMoveToPoint(ctx, xAxisWidth - 6, yAxisHeight - 3); |
| 446 | - CGContextAddLineToPoint(ctx, CGRectGetWidth(rect) - _chartMargin, _chartMargin + _chartCavanHeight); | 451 | + CGContextAddLineToPoint(ctx, xAxisWidth, yAxisHeight); |
| 447 | - CGContextAddLineToPoint(ctx, CGRectGetWidth(rect) - _chartMargin - 8, _chartMargin + _chartCavanHeight + 4); | 452 | + CGContextAddLineToPoint(ctx, xAxisWidth - 6, yAxisHeight + 3); |
| 448 | CGContextStrokePath(ctx); | 453 | CGContextStrokePath(ctx); |
| 449 | 454 | ||
| 455 | + if (self.showLabel) { | ||
| 456 | + | ||
| 457 | + // draw x axis separator | ||
| 458 | + CGPoint point; | ||
| 459 | + for (NSUInteger i = 0; i < [self.xLabels count]; i++) { | ||
| 460 | + point = CGPointMake(2 * _chartMargin + (i * _xLabelWidth), _chartMargin + _chartCavanHeight); | ||
| 461 | + CGContextMoveToPoint(ctx, point.x, point.y - 2); | ||
| 462 | + CGContextAddLineToPoint(ctx, point.x, point.y); | ||
| 463 | + CGContextStrokePath(ctx); | ||
| 464 | + } | ||
| 465 | + | ||
| 466 | + // draw y axis separator | ||
| 467 | + CGFloat yStepHeight = _chartCavanHeight / _yLabelNum; | ||
| 468 | + for (NSUInteger i = 0; i < [self.xLabels count]; i++) { | ||
| 469 | + point = CGPointMake(_chartMargin + yAsixOffset, (_chartCavanHeight - i * yStepHeight + _yLabelHeight/2)); | ||
| 470 | + CGContextMoveToPoint(ctx, point.x, point.y); | ||
| 471 | + CGContextAddLineToPoint(ctx, point.x + 2, point.y); | ||
| 472 | + CGContextStrokePath(ctx); | ||
| 473 | + } | ||
| 474 | + } | ||
| 475 | + | ||
| 450 | UIFont *font = [UIFont systemFontOfSize:11]; | 476 | UIFont *font = [UIFont systemFontOfSize:11]; |
| 451 | // draw y unit | 477 | // draw y unit |
| 452 | if ([self.yUnit length]) { | 478 | if ([self.yUnit length]) { |
-
Please register or login to post a comment