2010-10-07 37 views
1

我發現Tapku圖http://duivesteyn.net/2010/03/07/iphone-sdk-implementing-the-tapku-graph-in-your-application/?utm_source=twitterfeed&utm_medium=twitteriPhone Tapku圖,我如何使用日期而不是數字?

...這看起來很酷且相當簡單實現

- (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{ 

不過,我想有在水平軸上的不是數字日期... alt text

任何想法?

+0

TKGraphViewPoint協議似乎有一個xLabel屬性 - 如果你設置了這個屬性會發生什麼? – deanWombourne 2010-10-07 13:00:48

回答

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

+0

但是,如何設置每個標籤的數據,我必須將其設置在只接受數字的數據數組中。感謝您一直以來的幫助。 – Jules 2010-10-08 06:07:41

+0

在你的圖上使用'setGraphWithDataPoints:'方法 - 獲取實現'TKGraphViewPoint'的對象數組。你的'GraphPoint'類是什麼樣的 - 我敢打賭它實現了TKGraphViewPoint。你可以把它添加到你的問題,所以我可以看看? – deanWombourne 2010-10-08 07:50:37

+0

我已經添加了一個日期,我必須更改initWithID,並且出現錯誤,警告:沒有'-initWithID:value:pDate:'方法找到http://img.skitch.com/20101008- knjt325e8efmr23ec1isdkfpnn.jpg – Jules 2010-10-08 12:19:57

相關問題