andi

merge

@@ -157,7 +157,7 @@ displayCountingLabel:(BOOL)displayCountingLabel @@ -157,7 +157,7 @@ displayCountingLabel:(BOOL)displayCountingLabel
157 [_circle addAnimation:pathAnimation forKey:@"strokeEndAnimation"]; 157 [_circle addAnimation:pathAnimation forKey:@"strokeEndAnimation"];
158 _circle.strokeEnd = [_current floatValue] / [_total floatValue]; 158 _circle.strokeEnd = [_current floatValue] / [_total floatValue];
159 159
160 - [_countingLabel countFrom:0 to:[_current floatValue] withDuration:self.duration]; 160 + [_countingLabel countFrom:0 to:[_current floatValue]/([_total floatValue]/100.0) withDuration:self.duration];
161 161
162 162
163 // Check if user wants to add a gradient from the start color to the bar color 163 // Check if user wants to add a gradient from the start color to the bar color
@@ -235,4 +235,4 @@ displayCountingLabel:(BOOL)displayCountingLabel @@ -235,4 +235,4 @@ displayCountingLabel:(BOOL)displayCountingLabel
235 _total = total; 235 _total = total;
236 } 236 }
237 237
238 -@end 238 +@end
@@ -104,6 +104,20 @@ @@ -104,6 +104,20 @@
104 } 104 }
105 } 105 }
106 106
  107 +- (CGFloat)computeEqualWidthForXLabels:(NSArray *)xLabels
  108 +{
  109 + CGFloat xLabelWidth;
  110 +
  111 + if (_showLabel) {
  112 + xLabelWidth = _chartCavanWidth / [xLabels count];
  113 + } else {
  114 + xLabelWidth = (self.frame.size.width) / [xLabels count];
  115 + }
  116 +
  117 + return xLabelWidth;
  118 +}
  119 +
  120 +
107 - (void)setXLabels:(NSArray *)xLabels 121 - (void)setXLabels:(NSArray *)xLabels
108 { 122 {
109 CGFloat xLabelWidth; 123 CGFloat xLabelWidth;
This diff is collapsed. Click to expand it.
@@ -27,4 +27,11 @@ @@ -27,4 +27,11 @@
27 return item; 27 return item;
28 } 28 }
29 29
  30 +- (void)setValue:(CGFloat)value{
  31 + NSAssert(value >= 0, @"value should >= 0");
  32 + if (value != _value){
  33 + _value = value;
  34 + }
  35 +}
  36 +
30 @end 37 @end
@@ -156,6 +156,24 @@ @@ -156,6 +156,24 @@
156 } 156 }
157 } 157 }
158 158
  159 +- (NSArray*) getAxisMinMax:(NSArray*)xValues
  160 +{
  161 + float min = [xValues[0] floatValue];
  162 + float max = [xValues[0] floatValue];
  163 + for (NSNumber *number in xValues)
  164 + {
  165 + if ([number floatValue] > max)
  166 + max = [number floatValue];
  167 +
  168 + if ([number floatValue] < min)
  169 + min = [number floatValue];
  170 + }
  171 + NSArray *result = @[[NSNumber numberWithFloat:min], [NSNumber numberWithFloat:max]];
  172 +
  173 +
  174 + return result;
  175 +}
  176 +
159 - (void)setAxisXLabel:(NSArray *)array { 177 - (void)setAxisXLabel:(NSArray *)array {
160 if(array.count == ++_AxisX_partNumber){ 178 if(array.count == ++_AxisX_partNumber){
161 [_axisX_labels removeAllObjects]; 179 [_axisX_labels removeAllObjects];
@@ -64,7 +64,6 @@ data02.getData = ^(NSUInteger index) { @@ -64,7 +64,6 @@ data02.getData = ^(NSUInteger index) {
64 64
65 lineChart.chartData = @[data01, data02]; 65 lineChart.chartData = @[data01, data02];
66 [lineChart strokeChart]; 66 [lineChart strokeChart];
67 -  
68 ``` 67 ```
69 68
70 [![](https://dl.dropboxusercontent.com/u/1599662/bar.png)](https://dl.dropboxusercontent.com/u/1599662/bar.png) 69 [![](https://dl.dropboxusercontent.com/u/1599662/bar.png)](https://dl.dropboxusercontent.com/u/1599662/bar.png)
@@ -150,6 +149,46 @@ CGPoint end = CGPointMake(80, 45); @@ -150,6 +149,46 @@ CGPoint end = CGPointMake(80, 45);
150 scatterChart.delegate = self; 149 scatterChart.delegate = self;
151 ``` 150 ```
152 151
  152 +#### Legend
  153 +
  154 +Legend has been added to PNChart for Line and Pie Charts. Legend items position can be stacked or in series.
  155 +
  156 +[![](https://dl.dropboxusercontent.com/u/4904447/pnchart_legend_1.png)](https://dl.dropboxusercontent.com/u/4904447/pnchart_legend_1.png)
  157 +
  158 +[![](https://dl.dropboxusercontent.com/u/4904447/pnchart_legend_2.png)](https://dl.dropboxusercontent.com/u/4904447/pnchart_legend_2.png)
  159 +
  160 +```objective-c
  161 +#import "PNChart.h"
  162 +
  163 +//For Line Chart
  164 +
  165 +//Add Line Titles for the Legend
  166 +data01.dataTitle = @"Alpha";
  167 +data02.dataTitle = @"Beta Beta Beta Beta";
  168 +
  169 +//Build the legend
  170 +self.lineChart.legendStyle = PNLegendItemStyleSerial;
  171 +self.lineChart.legendFontSize = 12.0;
  172 +UIView *legend = [self.lineChart getLegendWithMaxWidth:320];
  173 +
  174 +//Move legend to the desired position and add to view
  175 +[legend setFrame:CGRectMake(100, 400, legend.frame.size.width, legend.frame.size.height)];
  176 +[self.view addSubview:legend];
  177 +
  178 +
  179 +//For Pie Chart
  180 +
  181 +//Build the legend
  182 +self.pieChart.legendStyle = PNLegendItemStyleStacked;
  183 +self.pieChart.legendFontSize = 12.0;
  184 +UIView *legend = [self.pieChart getLegendWithMaxWidth:200];
  185 +
  186 +//Move legend to the desired position and add to view
  187 +[legend setFrame:CGRectMake(130, 350, legend.frame.size.width, legend.frame.size.height)];
  188 +[self.view addSubview:legend];
  189 +```
  190 +
  191 +
153 #### Update Value 192 #### Update Value
154 193
155 Now it's easy to update value in real time 194 Now it's easy to update value in real time