kevinzhow

Merge branch 'independant-margins-bar-chart' of https://github.com/openhood/PNCh…

…art into openhood-independant-margins-bar-chart
@@ -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;
This diff is collapsed. Click to expand it.
@@ -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;