dullgrass

fix bug - unsupport yLabels

@@ -72,7 +72,7 @@ @@ -72,7 +72,7 @@
72 //make the _yLabelSum value dependant of the distinct values of yValues to avoid duplicates on yAxis 72 //make the _yLabelSum value dependant of the distinct values of yValues to avoid duplicates on yAxis
73 int yLabelsDifTotal = (int)[NSSet setWithArray:yValues].count; 73 int yLabelsDifTotal = (int)[NSSet setWithArray:yValues].count;
74 74
75 - // !!!: 调整Y坐标的显示 75 + // !!!: 生效Y轴坐标的最大
76 if (_yLabelSum==defaultYSum) { 76 if (_yLabelSum==defaultYSum) {
77 _yLabelSum = yLabelsDifTotal % 2 == 0 ? yLabelsDifTotal : yLabelsDifTotal + 1; 77 _yLabelSum = yLabelsDifTotal % 2 == 0 ? yLabelsDifTotal : yLabelsDifTotal + 1;
78 } 78 }
@@ -85,7 +85,7 @@ @@ -85,7 +85,7 @@
85 85
86 if (_yChartLabels) { 86 if (_yChartLabels) {
87 [self viewCleanupForCollection:_yChartLabels]; 87 [self viewCleanupForCollection:_yChartLabels];
88 - }else{ 88 + } else {
89 _yLabels = [NSMutableArray new]; 89 _yLabels = [NSMutableArray new];
90 } 90 }
91 91
@@ -93,52 +93,59 @@ @@ -93,52 +93,59 @@
93 //Add y labels 93 //Add y labels
94 float yLabelSectionHeight = (self.frame.size.height - _chartMargin * 2 - kXLabelHeight) / _yLabelSum; 94 float yLabelSectionHeight = (self.frame.size.height - _chartMargin * 2 - kXLabelHeight) / _yLabelSum;
95 95
96 - // !!!: 用户自行修改Y轴坐标值 96 + [self __addYCoordinateLabelsValuesWithyLabelSectionHeight:yLabelSectionHeight];
97 - if (_yLabels) { 97 +
98 - 98 + }
99 - [self getYValueMax:_yLabels]; 99 +}
100 -  
101 - for (int i=0; i<_yLabels.count; i++) {  
102 - float yAsixValues=[[_yLabels objectAtIndex:_yLabels.count-i-1] floatValue];  
103 - NSString *labelText= _yLabelFormatter(yAsixValues);  
104 -  
105 -  
106 -  
107 - PNChartLabel * label = [[PNChartLabel alloc] initWithFrame:CGRectMake(0,  
108 - yLabelSectionHeight * i + _chartMargin - kYLabelHeight/2.0,  
109 - _yChartLabelWidth,  
110 - kYLabelHeight)];  
111 - label.font = _labelFont;  
112 - label.textColor = _labelTextColor;  
113 - [label setTextAlignment:NSTextAlignmentRight];  
114 - label.text = labelText;  
115 -  
116 - [_yChartLabels addObject:label];  
117 - [self addSubview:label];  
118 -  
119 - }  
120 -  
121 - }else{  
122 100
123 - for (int index = 0; index < _yLabelSum; index++) { 101 +#pragma mark - Private Method
124 - 102 +#pragma mark - 添加柱状图的Y轴坐标
125 - NSString *labelText = _yLabelFormatter((float)_yValueMax * ( (_yLabelSum - index) / (float)_yLabelSum )); 103 +- (void)__addYCoordinateLabelsValuesWithyLabelSectionHeight:(float)yLabelSectionHeight{
126 - 104 +
127 - PNChartLabel * label = [[PNChartLabel alloc] initWithFrame:CGRectMake(0, 105 + if (_yLabels) {
128 - yLabelSectionHeight * index + _chartMargin - kYLabelHeight/2.0, 106 +
129 - _yChartLabelWidth, 107 + [self getYValueMax:_yLabels];
130 - kYLabelHeight)]; 108 +
131 - label.font = _labelFont; 109 + for (int i=0; i<_yLabels.count; i++) {
132 - label.textColor = _labelTextColor; 110 + float yAsixValues=[[_yLabels objectAtIndex:_yLabels.count-i-1] floatValue];
133 - [label setTextAlignment:NSTextAlignmentRight]; 111 + NSString *labelText= _yLabelFormatter(yAsixValues);
134 - label.text = labelText; 112 +
135 - 113 +
136 - [_yChartLabels addObject:label]; 114 +
137 - [self addSubview:label]; 115 + PNChartLabel * label = [[PNChartLabel alloc] initWithFrame:CGRectMake(0,
138 - 116 + yLabelSectionHeight * i + _chartMargin - kYLabelHeight/2.0,
139 - } 117 + _yChartLabelWidth,
140 - } 118 + kYLabelHeight)];
  119 + label.font = _labelFont;
  120 + label.textColor = _labelTextColor;
  121 + [label setTextAlignment:NSTextAlignmentRight];
  122 + label.text = labelText;
  123 +
  124 + [_yChartLabels addObject:label];
  125 + [self addSubview:label];
  126 +
  127 + }
  128 +
  129 + }else{
  130 +
  131 + for (int index = 0; index < _yLabelSum; index++) {
  132 +
  133 + NSString *labelText = _yLabelFormatter((float)_yValueMax * ( (_yLabelSum - index) / (float)_yLabelSum ));
  134 +
  135 + PNChartLabel * label = [[PNChartLabel alloc] initWithFrame:CGRectMake(0,
  136 + yLabelSectionHeight * index + _chartMargin - kYLabelHeight/2.0,
  137 + _yChartLabelWidth,
  138 + kYLabelHeight)];
  139 + label.font = _labelFont;
  140 + label.textColor = _labelTextColor;
  141 + [label setTextAlignment:NSTextAlignmentRight];
  142 + label.text = labelText;
  143 +
  144 + [_yChartLabels addObject:label];
  145 + [self addSubview:label];
  146 +
141 } 147 }
  148 + }
142 } 149 }
143 150
144 -(void)updateChartData:(NSArray *)data{ 151 -(void)updateChartData:(NSArray *)data{