Showing
3 changed files
with
13 additions
and
2 deletions
| @@ -88,6 +88,9 @@ typedef NSString *(^PNYLabelFormatter)(CGFloat yLabelValue); | @@ -88,6 +88,9 @@ typedef NSString *(^PNYLabelFormatter)(CGFloat yLabelValue); | ||
| 88 | /** Controls whether each bar should have a gradient fill. */ | 88 | /** Controls whether each bar should have a gradient fill. */ |
| 89 | @property (nonatomic) UIColor *barColorGradientStart; | 89 | @property (nonatomic) UIColor *barColorGradientStart; |
| 90 | 90 | ||
| 91 | +/** Controls whether text for x-axis be straight or rotate 45 degree. */ | ||
| 92 | +@property (nonatomic) BOOL rotateForXAxisText; | ||
| 93 | + | ||
| 91 | @property (nonatomic, retain) id<PNChartDelegate> delegate; | 94 | @property (nonatomic, retain) id<PNChartDelegate> delegate; |
| 92 | 95 | ||
| 93 | @end | 96 | @end |
| @@ -41,6 +41,7 @@ | @@ -41,6 +41,7 @@ | ||
| 41 | _barRadius = 2.0; | 41 | _barRadius = 2.0; |
| 42 | _showChartBorder = NO; | 42 | _showChartBorder = NO; |
| 43 | _yChartLabelWidth = 18; | 43 | _yChartLabelWidth = 18; |
| 44 | + _rotateForXAxisText = false; | ||
| 44 | } | 45 | } |
| 45 | 46 | ||
| 46 | return self; | 47 | return self; |
| @@ -106,8 +107,14 @@ | @@ -106,8 +107,14 @@ | ||
| 106 | [label setTextAlignment:NSTextAlignmentCenter]; | 107 | [label setTextAlignment:NSTextAlignmentCenter]; |
| 107 | label.text = labelText; | 108 | label.text = labelText; |
| 108 | [label sizeToFit]; | 109 | [label sizeToFit]; |
| 109 | - CGFloat labelXPosition = (index * _xLabelWidth + _chartMargin + _xLabelWidth /2.0 ); | 110 | + CGFloat labelXPosition; |
| 110 | - | 111 | + if (_rotateForXAxisText){ |
| 112 | + label.transform = CGAffineTransformMakeRotation(M_PI / 4); | ||
| 113 | + labelXPosition = (index * _xLabelWidth + _chartMargin + _xLabelWidth /1.5); | ||
| 114 | + } | ||
| 115 | + else{ | ||
| 116 | + labelXPosition = (index * _xLabelWidth + _chartMargin + _xLabelWidth /2.0 ); | ||
| 117 | + } | ||
| 111 | label.center = CGPointMake(labelXPosition, | 118 | label.center = CGPointMake(labelXPosition, |
| 112 | self.frame.size.height - xLabelHeight - _chartMargin + label.frame.size.height /2.0 + _labelMarginTop); | 119 | self.frame.size.height - xLabelHeight - _chartMargin + label.frame.size.height /2.0 + _labelMarginTop); |
| 113 | labelAddCount = 0; | 120 | labelAddCount = 0; |
| @@ -84,6 +84,7 @@ | @@ -84,6 +84,7 @@ | ||
| 84 | }; | 84 | }; |
| 85 | self.barChart.labelMarginTop = 5.0; | 85 | self.barChart.labelMarginTop = 5.0; |
| 86 | [self.barChart setXLabels:@[@"SEP 1",@"SEP 2",@"SEP 3",@"SEP 4",@"SEP 5",@"SEP 6",@"SEP 7"]]; | 86 | [self.barChart setXLabels:@[@"SEP 1",@"SEP 2",@"SEP 3",@"SEP 4",@"SEP 5",@"SEP 6",@"SEP 7"]]; |
| 87 | + self.barChart.rotateForXAxisText = true ; | ||
| 87 | [self.barChart setYValues:@[@1,@24,@12,@18,@30,@10,@21]]; | 88 | [self.barChart setYValues:@[@1,@24,@12,@18,@30,@10,@21]]; |
| 88 | [self.barChart setStrokeColors:@[PNGreen,PNGreen,PNRed,PNGreen,PNGreen,PNYellow,PNGreen]]; | 89 | [self.barChart setStrokeColors:@[PNGreen,PNGreen,PNRed,PNGreen,PNGreen,PNYellow,PNGreen]]; |
| 89 | // Adding gradient | 90 | // Adding gradient |
-
Please register or login to post a comment