我想在iphone上使用coreplot繪製一個XY圖,其中x軸上的日期和y軸上的一些值。參考使用coreplot SDK發佈的DatePlot示例,我能夠以月爲單位在x軸上繪製日期圖形(即x從月份的1日期到最後日期)。現在我想要一個年度量表,即我想在x軸上顯示所有月份名稱(1月,2月,3月等),並將我的剔號間隔顯示爲一個月的時間。在x軸上的月份的核心圖(iphone)
我用下面的代碼顯示值月度規模現在
oneXUnit = 60 * 60 * 24;
x.majorIntervalLength = CPDecimalFromFloat((float) oneXUnit);
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init]autorelease];
NSString *dateString = @"0";
[dateFormatter setDateFormat:@"MM"];
CPTimeFormatter *timeFormatter = [[CPTimeFormatter alloc]initWithDateFormatter:dateFormatter];
timeFormatter.referenceDate = [dateFormatter dateFromString:dateString];
x.labelFormatter = timeFormatter;
對於每年的模式X剔inteval需要爲一個月。我試了下面的代碼,但沒有工作
oneXUnit = 60 * 60 * 24 * 30;
x.majorIntervalLength = CPDecimalFromFloat((float) oneXUnit);
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init]autorelease];
NSString *dateString = @"Jan";
[dateFormatter setDateFormat:@"MMM"];
CPTimeFormatter *timeFormatter = [[CPTimeFormatter alloc]initWithDateFormatter:dateFormatter];
timeFormatter.referenceDate = [dateFormatter dateFromString:dateString];
x.labelFormatter = timeFormatter;
我認爲這種邏輯失敗,因爲每個月的天數是不同的。現在有幾個月在x軸上顯示,但它顯示爲
一月,三月,四月,五月,五月,六月,七月,八月,九月,十月,十一月,十二月。
您可以看到沒有Feb,並且有5個條目。我的滴答時間間隔如何與每個月的天數相關聯。任何解決方案 感謝和問候,
我有一個問題,因爲我用CPTAxisLabelingPolicyAutomatic,當我放大縮小,x軸已被重新繪製成1到10。 – nullmicgo 2012-02-13 03:39:33