kevinzhow

Fix #210

@@ -76,27 +76,33 @@ @@ -76,27 +76,33 @@
76 76
77 if (_showLabel) { 77 if (_showLabel) {
78 [self __addYCoordinateLabelsValues]; 78 [self __addYCoordinateLabelsValues];
  79 + } else {
  80 + [self processYMaxValue];
79 } 81 }
80 } 82 }
81 83
  84 +- (void)processYMaxValue {
  85 + NSArray *yAxisValues = _yLabels ? _yLabels : _yValues;
  86 + _yLabelSum = _yLabels ? _yLabels.count - 1 :_yLabelSum;
  87 + if (_yMaxValue) {
  88 + _yValueMax = _yMaxValue;
  89 + } else {
  90 + [self getYValueMax:yAxisValues];
  91 + }
  92 +
  93 + if (_yLabelSum==4) {
  94 + _yLabelSum = yAxisValues.count;
  95 + (_yLabelSum % 2 == 0) ? _yLabelSum : _yLabelSum++;
  96 + }
  97 +}
  98 +
82 #pragma mark - Private Method 99 #pragma mark - Private Method
83 #pragma mark - 添加柱状图的Y轴坐标 100 #pragma mark - 添加柱状图的Y轴坐标
84 - (void)__addYCoordinateLabelsValues{ 101 - (void)__addYCoordinateLabelsValues{
85 102
86 [self viewCleanupForCollection:_yChartLabels]; 103 [self viewCleanupForCollection:_yChartLabels];
87 104
88 - NSArray *yAxisValues = _yLabels ? _yLabels : _yValues; 105 + [self processYMaxValue];
89 - _yLabelSum = _yLabels ? _yLabels.count - 1 :_yLabelSum;  
90 - if (_yMaxValue) {  
91 - _yValueMax = _yMaxValue;  
92 - } else {  
93 - [self getYValueMax:yAxisValues];  
94 - }  
95 -  
96 - if (_yLabelSum==4) {  
97 - _yLabelSum = yAxisValues.count;  
98 - (_yLabelSum % 2 == 0) ? _yLabelSum : _yLabelSum++;  
99 - }  
100 106
101 float sectionHeight = (self.frame.size.height - _chartMargin * 2 - kXLabelHeight) / _yLabelSum; 107 float sectionHeight = (self.frame.size.height - _chartMargin * 2 - kXLabelHeight) / _yLabelSum;
102 for (int i = 0; i <= _yLabelSum; i++) { 108 for (int i = 0; i <= _yLabelSum; i++) {
@@ -94,6 +94,7 @@ @@ -94,6 +94,7 @@
94 self.titleLabel.text = @"Bar Chart"; 94 self.titleLabel.text = @"Bar Chart";
95 95
96 self.barChart = [[PNBarChart alloc] initWithFrame:CGRectMake(0, 135.0, SCREEN_WIDTH, 200.0)]; 96 self.barChart = [[PNBarChart alloc] initWithFrame:CGRectMake(0, 135.0, SCREEN_WIDTH, 200.0)];
  97 + self.barChart.showLabel = NO;
97 self.barChart.backgroundColor = [UIColor clearColor]; 98 self.barChart.backgroundColor = [UIColor clearColor];
98 self.barChart.yLabelFormatter = ^(CGFloat yValue){ 99 self.barChart.yLabelFormatter = ^(CGFloat yValue){
99 CGFloat yValueParsed = yValue; 100 CGFloat yValueParsed = yValue;
@@ -108,6 +109,7 @@ @@ -108,6 +109,7 @@
108 [self.barChart setStrokeColors:@[PNGreen,PNGreen,PNRed,PNGreen,PNGreen,PNGreen,PNRed,PNGreen]]; 109 [self.barChart setStrokeColors:@[PNGreen,PNGreen,PNRed,PNGreen,PNGreen,PNGreen,PNRed,PNGreen]];
109 self.barChart.isGradientShow = NO; 110 self.barChart.isGradientShow = NO;
110 self.barChart.isShowNumbers = NO; 111 self.barChart.isShowNumbers = NO;
  112 +
111 [self.barChart strokeChart]; 113 [self.barChart strokeChart];
112 114
113 self.barChart.delegate = self; 115 self.barChart.delegate = self;