dullgrass

FIXBUG: BarChart Show Wrong Numbers

@@ -64,7 +64,7 @@ @@ -64,7 +64,7 @@
64 _yChartLabelWidth = 18; 64 _yChartLabelWidth = 18;
65 _rotateForXAxisText = false; 65 _rotateForXAxisText = false;
66 } 66 }
67 - 67 +/*
68 - (void)setYValues:(NSArray *)yValues 68 - (void)setYValues:(NSArray *)yValues
69 { 69 {
70 _yValues = yValues; 70 _yValues = yValues;
@@ -147,6 +147,53 @@ @@ -147,6 +147,53 @@
147 } 147 }
148 } 148 }
149 } 149 }
  150 +*/
  151 +
  152 +- (void)setYValues:(NSArray *)yValues
  153 +{
  154 + _yValues = yValues;
  155 +
  156 + if (_showLabel) {
  157 + [self __addYCoordinateLabelsValues];
  158 + }
  159 +}
  160 +
  161 +#pragma mark - Private Method
  162 +- (void)__addYCoordinateLabelsValues
  163 +{
  164 + [self viewCleanupForCollection:_yChartLabels];
  165 +
  166 + NSArray *yAxisValues = _yLabels ? _yLabels : _yValues;
  167 + if (_yMaxValue) {
  168 + _yValueMax = _yMaxValue;
  169 + } else {
  170 + [self getYValueMax:yAxisValues];
  171 + }
  172 +
  173 + _yLabelSum = yAxisValues.count;
  174 + (_yLabelSum % 2 == 0) ? _yLabelSum : _yLabelSum++;
  175 +
  176 + float sectionHeight = (self.frame.size.height - _chartMargin * 2 - kXLabelHeight) / _yLabelSum;
  177 + for (int i = 0; i < _yLabelSum; i++) {
  178 + NSString *labelText;
  179 + if (_yLabels) {
  180 + float yAsixValue = [_yLabels[_yLabels.count - i - 1] floatValue];
  181 + labelText= _yLabelFormatter(yAsixValue);
  182 + } else {
  183 + labelText = _yLabelFormatter((float)_yValueMax * ( (_yLabelSum - i) / (float)_yLabelSum ));
  184 + }
  185 +
  186 + CGRect frame = (CGRect){0, sectionHeight * i + _chartMargin - kYLabelHeight/2.0, _yChartLabelWidth, kYLabelHeight};
  187 + PNChartLabel *label = [[PNChartLabel alloc] initWithFrame:frame];
  188 + label.font = _labelFont;
  189 + label.textColor = _labelTextColor;
  190 + [label setTextAlignment:NSTextAlignmentRight];
  191 + label.text = labelText;
  192 + [self addSubview:label];
  193 +
  194 + [_yChartLabels addObject:label];
  195 + }
  196 +}
150 197
151 -(void)updateChartData:(NSArray *)data{ 198 -(void)updateChartData:(NSArray *)data{
152 self.yValues = data; 199 self.yValues = data;