tags:

views:

37

answers:

1

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];

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...alt text

Any ideas?

+1  A: 

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.

deanWombourne
But how do I set the data for each label, I'd have to set it in the data array which only accepts numbers. Thanks for your help so far.
Jules
Use the `setGraphWithDataPoints:` method on your graph - that takes an array of objects which implement `TKGraphViewPoint`. What does your `GraphPoint` class look like - I bet it implements TKGraphViewPoint. Can you add it to your question so I can have a look?
deanWombourne
I've added a date, and I've had to change initWithID and I'm getting an error, warning: no '-initWithID:value:pDate:' method found http://img.skitch.com/20101008-knjt325e8efmr23ec1isdkfpnn.jpg
Jules
That's just a little typo; the line in your .h and .m files should read `- (id)initWithID:(int)pkv value:(NSNumber *)number pDate:(NSDate *)pDate;` :)
deanWombourne
no, initWithID is nothing special - can you show me what you have now, you shouldn't be getting the same warning at all!
deanWombourne