我找到了Tapku Graph http://duivesteyn.net/2010/03/07/iphone-sdk-implementing-the-tapku-graph-in-your-application/?utm_source=twitterfeed&utm_medium=twitter
......看起来很酷且很容易实现
- (void) thread{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
srand([[NSDate date] timeIntervalSince1970]);
for(int i=0;i<100;i++){
//int no = rand() % 100 + i;
int no = 10 + i;
//I've changed the above value to prove that heres
//where you supply your data
GraphPoint *gp = [[GraphPoint alloc] initWithID:i value:[NSNumber numberWithFloat:no]];
[data addObject:gp];
[gp release];
}
//Heres where the data is drawn
- (void) drawXAxisLabelsWithContext:(CGContextRef) context{
但是我希望横轴上有日期而不是数字......
有什么想法吗?
答案 0 :(得分:2)
查看源没有github,GraphView.m的第293行将x轴标签设置为图表上每个点指定的字符串:
lab.text = [d xLabel];
所以为了让它显示日期,我只是像这样实现TKGraphViewPoint协议:
-(NSString *)xLabel {
NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease];
[formatter setDateFormat:@"EEE, MMM d, yyyy"]; // i.e. Wed, July 10, 2010
return [formatter stringFromDate:myDate];
}
(假设您的GraphPoint具有NSData * myDate属性:)
日期格式字符串选项can be found here。