Two issues:
1) Bar plots don't respect the majorIntervalLength when plotting --
the bars are always placed on integral units. So a trick like setting
the interval to 24*60*60 to display daily values won't work.
2) Changing the x scale just to make CPTTimeFormatter happy is counter-
intuitive. The "oneDay" constants in the Plot Gallery app proves
this :-)
When you're plotting time intervals, you have a priori knowledge of
the date range you're working with. Applying this knowledge to the
axes is wrong, in my opinion. It makes more sense to apply that
knowledge to the formatter itself.
I've created a CPTCalendarFormatter class that you can use like this
to display daily data along the x axis:
CPTXYAxis *x = axisSet.xAxis;
{
x.majorIntervalLength = CPTDecimalFromInteger(1);
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init]
autorelease];
dateFormatter.dateStyle = kCFDateFormatterShortStyle;
CPTCalendarFormatter *calendarFormatter = [[[CPTCalendarFormatter
alloc] initWithDateFormatter:dateFormatter] autorelease];
calendarFormatter.referenceDate = [NSDate date];
calendarFormatter.referenceCalendarUnit = NSDayCalendarUnit;
x.labelFormatter = calendarFormatter;
}
If you're working with months or years, it's just a matter of changing
to NSMonthCalendarUnit or NSYearCalendarUnit.
I'm not going to learn Mecurial just to add this to the project, so
you can download the code from here:
http://files.iconfactory.net/craig/whatever/CPTCalendarFormatter.zip
Enjoy!