dullgrass

no message

@@ -64,94 +64,11 @@ @@ -64,94 +64,11 @@
64 _yChartLabelWidth = 18; 64 _yChartLabelWidth = 18;
65 _rotateForXAxisText = false; 65 _rotateForXAxisText = false;
66 } 66 }
67 -/*  
68 -- (void)setYValues:(NSArray *)yValues  
69 -{  
70 - _yValues = yValues;  
71 -  
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;  
74 -  
75 - // !!!: 生效Y轴坐标的最大值  
76 - if (_yLabelSum==defaultYSum) {  
77 - _yLabelSum = yLabelsDifTotal % 2 == 0 ? yLabelsDifTotal : yLabelsDifTotal + 1;  
78 - }  
79 -  
80 - if (_yMaxValue) {  
81 - _yValueMax = _yMaxValue;  
82 - } else {  
83 - [self getYValueMax:yValues];  
84 - }  
85 -  
86 - if (_yChartLabels) {  
87 - [self viewCleanupForCollection:_yChartLabels];  
88 - } else {  
89 - _yLabels = [NSMutableArray new];  
90 - }  
91 -  
92 - if (_showLabel) {  
93 - //Add y labels  
94 - float yLabelSectionHeight = (self.frame.size.height - _chartMargin * 2 - kXLabelHeight) / _yLabelSum;  
95 -  
96 - [self __addYCoordinateLabelsValuesWithyLabelSectionHeight:yLabelSectionHeight];  
97 -  
98 - }  
99 -}  
100 -  
101 -#pragma mark - Private Method  
102 -#pragma mark - 添加柱状图的Y轴坐标  
103 -- (void)__addYCoordinateLabelsValuesWithyLabelSectionHeight:(float)yLabelSectionHeight{  
104 -  
105 - if (_yLabels) {  
106 -  
107 - [self getYValueMax:_yLabels];  
108 -  
109 - for (int i=0; i<_yLabels.count; i++) {  
110 - float yAsixValues=[[_yLabels objectAtIndex:_yLabels.count-i-1] floatValue];  
111 - NSString *labelText= _yLabelFormatter(yAsixValues);  
112 -  
113 -  
114 -  
115 - PNChartLabel * label = [[PNChartLabel alloc] initWithFrame:CGRectMake(0,  
116 - yLabelSectionHeight * i + _chartMargin - kYLabelHeight/2.0,  
117 - _yChartLabelWidth,  
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 -  
147 - }  
148 - }  
149 -}  
150 -*/  
151 67
152 - (void)setYValues:(NSArray *)yValues 68 - (void)setYValues:(NSArray *)yValues
153 { 69 {
154 - _yValues = yValues; 70 + _yValues = yValues;
  71 + //make the _yLabelSum value dependant of the distinct values of yValues to avoid duplicates on yAxis
155 72
156 if (_showLabel) { 73 if (_showLabel) {
157 [self __addYCoordinateLabelsValues]; 74 [self __addYCoordinateLabelsValues];
@@ -159,8 +76,9 @@ @@ -159,8 +76,9 @@
159 } 76 }
160 77
161 #pragma mark - Private Method 78 #pragma mark - Private Method
162 -- (void)__addYCoordinateLabelsValues 79 +#pragma mark - 添加柱状图的Y轴坐标
163 -{ 80 +- (void)__addYCoordinateLabelsValues{
  81 +
164 [self viewCleanupForCollection:_yChartLabels]; 82 [self viewCleanupForCollection:_yChartLabels];
165 83
166 NSArray *yAxisValues = _yLabels ? _yLabels : _yValues; 84 NSArray *yAxisValues = _yLabels ? _yLabels : _yValues;
@@ -169,9 +87,11 @@ @@ -169,9 +87,11 @@
169 } else { 87 } else {
170 [self getYValueMax:yAxisValues]; 88 [self getYValueMax:yAxisValues];
171 } 89 }
172 - 90 +
173 - _yLabelSum = yAxisValues.count; 91 + if (_yLabelSum==defaultYSum) {
174 - (_yLabelSum % 2 == 0) ? _yLabelSum : _yLabelSum++; 92 + _yLabelSum = yAxisValues.count;
  93 + (_yLabelSum % 2 == 0) ? _yLabelSum : _yLabelSum++;
  94 + }
175 95
176 float sectionHeight = (self.frame.size.height - _chartMargin * 2 - kXLabelHeight) / _yLabelSum; 96 float sectionHeight = (self.frame.size.height - _chartMargin * 2 - kXLabelHeight) / _yLabelSum;
177 for (int i = 0; i < _yLabelSum; i++) { 97 for (int i = 0; i < _yLabelSum; i++) {
@@ -195,6 +115,8 @@ @@ -195,6 +115,8 @@
195 } 115 }
196 } 116 }
197 117
  118 +
  119 +
198 -(void)updateChartData:(NSArray *)data{ 120 -(void)updateChartData:(NSArray *)data{
199 self.yValues = data; 121 self.yValues = data;
200 [self updateBar]; 122 [self updateBar];
@@ -324,7 +246,7 @@ @@ -324,7 +246,7 @@
324 float value = [valueString floatValue]; 246 float value = [valueString floatValue];
325 247
326 float grade = (float)value / (float)_yValueMax; 248 float grade = (float)value / (float)_yValueMax;
327 - 249 +
328 if (isnan(grade)) { 250 if (isnan(grade)) {
329 grade = 0; 251 grade = 0;
330 } 252 }