Allow setting Top/Bottom/Left/Right margins independently in PNBarChart
Showing
3 changed files
with
20 additions
and
4 deletions
| @@ -46,7 +46,10 @@ typedef NSString *(^PNYLabelFormatter)(CGFloat yLabelValue); | @@ -46,7 +46,10 @@ typedef NSString *(^PNYLabelFormatter)(CGFloat yLabelValue); | ||
| 46 | /** Formats the ylabel text. */ | 46 | /** Formats the ylabel text. */ |
| 47 | @property (copy) PNYLabelFormatter yLabelFormatter; | 47 | @property (copy) PNYLabelFormatter yLabelFormatter; |
| 48 | 48 | ||
| 49 | -@property (nonatomic) CGFloat chartMargin; | 49 | +@property (nonatomic) CGFloat chartMarginLeft; |
| 50 | +@property (nonatomic) CGFloat chartMarginRight; | ||
| 51 | +@property (nonatomic) CGFloat chartMarginTop; | ||
| 52 | +@property (nonatomic) CGFloat chartMarginBottom; | ||
| 50 | 53 | ||
| 51 | /** Controls whether labels should be displayed. */ | 54 | /** Controls whether labels should be displayed. */ |
| 52 | @property (nonatomic) BOOL showLabel; | 55 | @property (nonatomic) BOOL showLabel; |
This diff is collapsed. Click to expand it.
| @@ -91,20 +91,33 @@ | @@ -91,20 +91,33 @@ | ||
| 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 | + self.barChart.yChartLabelWidth = 60.0; | ||
| 110 | + self.barChart.chartMarginLeft = 70.0; | ||
| 111 | + self.barChart.chartMarginRight = 10.0; | ||
| 112 | + self.barChart.chartMarginTop = 5.0; | ||
| 113 | + self.barChart.chartMarginBottom = 10.0; | ||
| 114 | + | ||
| 115 | + | ||
| 104 | self.barChart.labelMarginTop = 5.0; | 116 | self.barChart.labelMarginTop = 5.0; |
| 105 | self.barChart.showChartBorder = YES; | 117 | self.barChart.showChartBorder = YES; |
| 106 | [self.barChart setXLabels:@[@"2",@"3",@"4",@"5",@"2",@"3",@"4",@"5"]]; | 118 | [self.barChart setXLabels:@[@"2",@"3",@"4",@"5",@"2",@"3",@"4",@"5"]]; |
| 107 | // self.barChart.yLabels = @[@-10,@0,@10]; | 119 | // self.barChart.yLabels = @[@-10,@0,@10]; |
| 120 | +// [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]]; | 121 | [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]]; | 122 | [self.barChart setStrokeColors:@[PNGreen,PNGreen,PNRed,PNGreen,PNGreen,PNGreen,PNRed,PNGreen]]; |
| 110 | self.barChart.isGradientShow = NO; | 123 | self.barChart.isGradientShow = NO; |
-
Please register or login to post a comment