kevinzhow

Fix barchart nan bug

@@ -118,6 +118,11 @@ typedef NSString *(^PNyLabelFromatter)(CGFloat yLabelValue); @@ -118,6 +118,11 @@ typedef NSString *(^PNyLabelFromatter)(CGFloat yLabelValue);
118 */ 118 */
119 @property (nonatomic) CGFloat yMaxValue; 119 @property (nonatomic) CGFloat yMaxValue;
120 120
  121 +/*
  122 + yMinValue define the min value of the chart
  123 + */
  124 +@property (nonatomic) CGFloat yMinValue;
  125 +
121 @property (nonatomic, retain) id<PNChartDelegate> delegate; 126 @property (nonatomic, retain) id<PNChartDelegate> delegate;
122 127
123 @end 128 @end
@@ -64,22 +64,13 @@ @@ -64,22 +64,13 @@
64 64
65 - (void)getYValueMax:(NSArray *)yLabels 65 - (void)getYValueMax:(NSArray *)yLabels
66 { 66 {
67 - NSInteger max = 0; 67 + int max = [[yLabels valueForKeyPath:@"@max.intValue"] intValue];
68 68
69 - for (NSString *valueString in yLabels) { 69 + _yValueMax = (int)max;
70 - NSInteger value = [valueString integerValue];  
71 -  
72 - if (value > max) {  
73 - max = value;  
74 - }  
75 - }  
76 70
77 - //Min value for Y label 71 + if (_yValueMax == 0) {
78 - if (max < 5) { 72 + _yValueMax = _yMinValue;
79 - max = 5;  
80 } 73 }
81 -  
82 - _yValueMax = (int)max;  
83 } 74 }
84 75
85 76
@@ -169,6 +160,11 @@ @@ -169,6 +160,11 @@
169 float value = [valueString floatValue]; 160 float value = [valueString floatValue];
170 161
171 float grade = (float)value / (float)_yValueMax; 162 float grade = (float)value / (float)_yValueMax;
  163 +
  164 + if (isnan(grade)) {
  165 + grade = 0;
  166 + }
  167 +
172 PNBar *bar; 168 PNBar *bar;
173 CGFloat barWidth; 169 CGFloat barWidth;
174 CGFloat barXPosition; 170 CGFloat barXPosition;