kevinzhow

Fix barchart nan bug

... ... @@ -118,6 +118,11 @@ typedef NSString *(^PNyLabelFromatter)(CGFloat yLabelValue);
*/
@property (nonatomic) CGFloat yMaxValue;
/*
yMinValue define the min value of the chart
*/
@property (nonatomic) CGFloat yMinValue;
@property (nonatomic, retain) id<PNChartDelegate> delegate;
@end
... ...
... ... @@ -64,22 +64,13 @@
- (void)getYValueMax:(NSArray *)yLabels
{
NSInteger max = 0;
int max = [[yLabels valueForKeyPath:@"@max.intValue"] intValue];
for (NSString *valueString in yLabels) {
NSInteger value = [valueString integerValue];
if (value > max) {
max = value;
}
}
_yValueMax = (int)max;
//Min value for Y label
if (max < 5) {
max = 5;
if (_yValueMax == 0) {
_yValueMax = _yMinValue;
}
_yValueMax = (int)max;
}
... ... @@ -169,6 +160,11 @@
float value = [valueString floatValue];
float grade = (float)value / (float)_yValueMax;
if (isnan(grade)) {
grade = 0;
}
PNBar *bar;
CGFloat barWidth;
CGFloat barXPosition;
... ...