dullgrass

fix bug - unsupport yLabels

... ... @@ -72,7 +72,7 @@
//make the _yLabelSum value dependant of the distinct values of yValues to avoid duplicates on yAxis
int yLabelsDifTotal = (int)[NSSet setWithArray:yValues].count;
// !!!: 调整Y坐标的显示
// !!!: 生效Y轴坐标的最大
if (_yLabelSum==defaultYSum) {
_yLabelSum = yLabelsDifTotal % 2 == 0 ? yLabelsDifTotal : yLabelsDifTotal + 1;
}
... ... @@ -85,7 +85,7 @@
if (_yChartLabels) {
[self viewCleanupForCollection:_yChartLabels];
}else{
} else {
_yLabels = [NSMutableArray new];
}
... ... @@ -93,52 +93,59 @@
//Add y labels
float yLabelSectionHeight = (self.frame.size.height - _chartMargin * 2 - kXLabelHeight) / _yLabelSum;
// !!!: 用户自行修改Y轴坐标值
if (_yLabels) {
[self getYValueMax:_yLabels];
for (int i=0; i<_yLabels.count; i++) {
float yAsixValues=[[_yLabels objectAtIndex:_yLabels.count-i-1] floatValue];
NSString *labelText= _yLabelFormatter(yAsixValues);
PNChartLabel * label = [[PNChartLabel alloc] initWithFrame:CGRectMake(0,
yLabelSectionHeight * i + _chartMargin - kYLabelHeight/2.0,
_yChartLabelWidth,
kYLabelHeight)];
label.font = _labelFont;
label.textColor = _labelTextColor;
[label setTextAlignment:NSTextAlignmentRight];
label.text = labelText;
[_yChartLabels addObject:label];
[self addSubview:label];
}
}else{
[self __addYCoordinateLabelsValuesWithyLabelSectionHeight:yLabelSectionHeight];
}
}
for (int index = 0; index < _yLabelSum; index++) {
NSString *labelText = _yLabelFormatter((float)_yValueMax * ( (_yLabelSum - index) / (float)_yLabelSum ));
PNChartLabel * label = [[PNChartLabel alloc] initWithFrame:CGRectMake(0,
yLabelSectionHeight * index + _chartMargin - kYLabelHeight/2.0,
_yChartLabelWidth,
kYLabelHeight)];
label.font = _labelFont;
label.textColor = _labelTextColor;
[label setTextAlignment:NSTextAlignmentRight];
label.text = labelText;
[_yChartLabels addObject:label];
[self addSubview:label];
}
}
#pragma mark - Private Method
#pragma mark - 添加柱状图的Y轴坐标
- (void)__addYCoordinateLabelsValuesWithyLabelSectionHeight:(float)yLabelSectionHeight{
if (_yLabels) {
[self getYValueMax:_yLabels];
for (int i=0; i<_yLabels.count; i++) {
float yAsixValues=[[_yLabels objectAtIndex:_yLabels.count-i-1] floatValue];
NSString *labelText= _yLabelFormatter(yAsixValues);
PNChartLabel * label = [[PNChartLabel alloc] initWithFrame:CGRectMake(0,
yLabelSectionHeight * i + _chartMargin - kYLabelHeight/2.0,
_yChartLabelWidth,
kYLabelHeight)];
label.font = _labelFont;
label.textColor = _labelTextColor;
[label setTextAlignment:NSTextAlignmentRight];
label.text = labelText;
[_yChartLabels addObject:label];
[self addSubview:label];
}
}else{
for (int index = 0; index < _yLabelSum; index++) {
NSString *labelText = _yLabelFormatter((float)_yValueMax * ( (_yLabelSum - index) / (float)_yLabelSum ));
PNChartLabel * label = [[PNChartLabel alloc] initWithFrame:CGRectMake(0,
yLabelSectionHeight * index + _chartMargin - kYLabelHeight/2.0,
_yChartLabelWidth,
kYLabelHeight)];
label.font = _labelFont;
label.textColor = _labelTextColor;
[label setTextAlignment:NSTextAlignmentRight];
label.text = labelText;
[_yChartLabels addObject:label];
[self addSubview:label];
}
}
}
-(void)updateChartData:(NSArray *)data{
... ...