I would like to draw an XY graph using coreplot on iphone with date on x axis and some values on y axis. Referring to the DatePlot example shipping with the coreplot SDK, I was able to draw graph with date on x axis on a monthly scale (ie x ranges from 1 date of the month to last date). Now I want an yearly scale , ie I want to show All month names (Jan,Feb,Mar etc) on x axis and my tick inteval as one month time.
I used following code for showing values in a monthly scale
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;
Now For yearly mode x tick inteval needs to be one month. I tried the below code , but didnt work
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;
I think this logic fails because number of days for each months are different. Now months are showing on x axis, but it is showing as
Jan,Mar,April,May,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec.
You can see that there is no Feb and there are 2 entries for May. How can my tick interval relates with the number of days with each month. Any solutions? Thanks and Regards,