开发者

iPhone Tapku Graph, how can I use dates instead on numbers?

I've found Tapku Graph http://duivesteyn.net/2010/03/07/iphone-sdk-implementing-the-tapku-graph-in-your-application/?utm_source=twitterfeed&utm_medium=twitter

... which looks cool and fairly simple to implement

- (void) thread{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init开发者_如何学Python];

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{

However I'd like to have dates on the horizontal axis instead of numbers...

iPhone Tapku Graph, how can I use dates instead on numbers?

Any ideas?


Looking at the source no github, line 293 of GraphView.m sets the x axis labels to be a string specified by each point on the graph :

lab.text = [d xLabel];

so to get it to display dates, I'd just implement the TKGraphViewPoint protocol like this :

-(NSString *)xLabel {
    NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease];
    [formatter setDateFormat:@"EEE, MMM d, yyyy"]; // i.e. Wed, July 10, 2010
    return [formatter stringFromDate:myDate];
}

(assuming that your GraphPoint has an NSData *myDate property :)

The date formatting string options can be found here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜