iphone上如何绘制点状图
2010-10-19 20:45:23 来源:WEB开发网156 endPos = (i+1)*IntervalValue;
157 }
158 else
159 {
160 endPos = [dataSource count];
161 }
162
163 for (int index=startPos; index<=endPos-1; ++index) {
164 oneGroupTotalValue += [[dataSource objectAtIndex:index] floatValue];
165 }
166
167 oneGroupAvageValue = oneGroupTotalValue/IntervalValue;
168 [dataSourceAfterPorcess addObject:[NSNumber numberWithFloat:oneGroupAvageValue]];
169 }
170}
171
172
173- (void)dealloc {
174 [super dealloc];
175}
176@end
177
178
179
180//-(UIImage*)createImage
181//{
182// CGSize size = CGSizeMake(32,32);
183// CGRect rect = CGRectMake(0, 0, 32, 32);
184// UIGraphicsBeginImageContext(size);
185// CGContextRef context = UIGraphicsGetCurrentContext();
186//
187// unsigned int red, green, blue;
188// // Fill color.
189// CGContextSetRGBFillColor(context, 0.7, 0.7, 0.7, 1.0);
190//
191// // Your drawing code.
192// CGContextFillEllipseInRect(context, rect);
193//
194// // Get the image and return.
195// UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
196// UIGraphicsEndImageContext();
197// return image;
198//}
调用处代码 *viewControler.m:
01CustomPolylineView* polyView = [[CustomPolylineView alloc] initWithFrame:CGRectMake(10,30, 200, 200)];
02NSArray* g = [NSArray arrayWithObjects:[NSNumber numberWithFloat:18.0],
03 [NSNumber numberWithFloat:21.0],
04 [NSNumber numberWithFloat:22.0],
05 [NSNumber numberWithFloat:32.0],
06 [NSNumber numberWithFloat:34.0],nil];
07
08polyView.dataSource = g;
09polyView.frame = CGRectOffset(polyView.frame, 0, 44);
10[self.view addSubview:polyView];
图上的紫色图片即可以使用代码生成,也可以直接使用图片。代码中已经将代码生成图片的代码注释掉
更多精彩
赞助商链接