Kevin

Merge pull request #22 from schneiderandre/master

Added support to define a color per bar.
@@ -108,6 +108,7 @@ @@ -108,6 +108,7 @@
108 barChart.backgroundColor = [UIColor clearColor]; 108 barChart.backgroundColor = [UIColor clearColor];
109 [barChart setXLabels:@[@"SEP 1",@"SEP 2",@"SEP 3",@"SEP 4",@"SEP 5",@"SEP 6",@"SEP 7"]]; 109 [barChart setXLabels:@[@"SEP 1",@"SEP 2",@"SEP 3",@"SEP 4",@"SEP 5",@"SEP 6",@"SEP 7"]];
110 [barChart setYValues:@[@1,@24,@12,@18,@30,@10,@21]]; 110 [barChart setYValues:@[@1,@24,@12,@18,@30,@10,@21]];
  111 + [barChart setStrokeColors:@[PNGreen,PNGreen,PNRed,PNGreen,PNGreen,PNYellow,PNGreen]];
111 [barChart strokeChart]; 112 [barChart strokeChart];
112 113
113 [viewController.view addSubview:barChartLabel]; 114 [viewController.view addSubview:barChartLabel];
@@ -33,6 +33,8 @@ @@ -33,6 +33,8 @@
33 33
34 @property (nonatomic, strong) UIColor * strokeColor; 34 @property (nonatomic, strong) UIColor * strokeColor;
35 35
  36 +@property (nonatomic, strong) NSArray * strokeColors;
  37 +
36 @property (nonatomic, strong) UIColor * barBackgroundColor; 38 @property (nonatomic, strong) UIColor * barBackgroundColor;
37 39
38 @property (nonatomic) BOOL showLabel; 40 @property (nonatomic) BOOL showLabel;
@@ -11,6 +11,10 @@ @@ -11,6 +11,10 @@
11 #import "PNChartLabel.h" 11 #import "PNChartLabel.h"
12 #import "PNBar.h" 12 #import "PNBar.h"
13 13
  14 +@interface PNBarChart()
  15 +- (UIColor *)barColorAtIndex:(NSUInteger)index;
  16 +@end
  17 +
14 @implementation PNBarChart 18 @implementation PNBarChart
15 19
16 - (id)initWithFrame:(CGRect)frame 20 - (id)initWithFrame:(CGRect)frame
@@ -97,7 +101,7 @@ @@ -97,7 +101,7 @@
97 bar = [[PNBar alloc] initWithFrame:CGRectMake((index * _xLabelWidth + chartMargin + _xLabelWidth * 0.25), self.frame.size.height - chartCavanHeight , _xLabelWidth * 0.6, chartCavanHeight)]; 101 bar = [[PNBar alloc] initWithFrame:CGRectMake((index * _xLabelWidth + chartMargin + _xLabelWidth * 0.25), self.frame.size.height - chartCavanHeight , _xLabelWidth * 0.6, chartCavanHeight)];
98 } 102 }
99 bar.backgroundColor = _barBackgroundColor; 103 bar.backgroundColor = _barBackgroundColor;
100 - bar.barColor = _strokeColor; 104 + bar.barColor = [self barColorAtIndex:index];
101 bar.grade = grade; 105 bar.grade = grade;
102 [self addSubview:bar]; 106 [self addSubview:bar];
103 107
@@ -105,4 +109,15 @@ @@ -105,4 +109,15 @@
105 } 109 }
106 } 110 }
107 111
  112 +#pragma mark - Class extension methods
  113 +
  114 +- (UIColor *)barColorAtIndex:(NSUInteger)index
  115 +{
  116 + if ([self.strokeColors count] == [self.yValues count]) {
  117 + return self.strokeColors[index];
  118 + } else {
  119 + return self.strokeColor;
  120 + }
  121 +}
  122 +
108 @end 123 @end