dullgrass

no message

@@ -64,103 +64,21 @@ @@ -64,103 +64,21 @@
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;
71 -  
72 //make the _yLabelSum value dependant of the distinct values of yValues to avoid duplicates on yAxis 71 //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 72
92 if (_showLabel) { 73 if (_showLabel) {
93 - //Add y labels 74 + [self __addYCoordinateLabelsValues];
94 - float yLabelSectionHeight = (self.frame.size.height - _chartMargin * 2 - kXLabelHeight) / _yLabelSum;  
95 -  
96 - [self __addYCoordinateLabelsValuesWithyLabelSectionHeight:yLabelSectionHeight];  
97 -  
98 } 75 }
99 } 76 }
100 77
101 #pragma mark - Private Method 78 #pragma mark - Private Method
102 #pragma mark - 添加柱状图的Y轴坐标 79 #pragma mark - 添加柱状图的Y轴坐标
103 -- (void)__addYCoordinateLabelsValuesWithyLabelSectionHeight:(float)yLabelSectionHeight{ 80 +- (void)__addYCoordinateLabelsValues{
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 -  
152 -- (void)setYValues:(NSArray *)yValues  
153 -{  
154 - _yValues = yValues;  
155 -  
156 - if (_showLabel) {  
157 - [self __addYCoordinateLabelsValues];  
158 - }  
159 -}  
160 81
161 -#pragma mark - Private Method  
162 -- (void)__addYCoordinateLabelsValues  
163 -{  
164 [self viewCleanupForCollection:_yChartLabels]; 82 [self viewCleanupForCollection:_yChartLabels];
165 83
166 NSArray *yAxisValues = _yLabels ? _yLabels : _yValues; 84 NSArray *yAxisValues = _yLabels ? _yLabels : _yValues;
@@ -170,8 +88,10 @@ @@ -170,8 +88,10 @@
170 [self getYValueMax:yAxisValues]; 88 [self getYValueMax:yAxisValues];
171 } 89 }
172 90
  91 + if (_yLabelSum==defaultYSum) {
173 _yLabelSum = yAxisValues.count; 92 _yLabelSum = yAxisValues.count;
174 (_yLabelSum % 2 == 0) ? _yLabelSum : _yLabelSum++; 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];