pj409
pj409

Reputation: 337

CorePlot: xAxis NSDateFormatter trouble

I'm making an app with coreplot and am trying to get my labels along the Xaxis to read 12pm , 1pm, 2pm, etc. I have successfully implemented NSDateFormatter into the xAxis.label formatter.

Problem is, the intervals appear to be in seconds (see pic below) I need them to be in hours.

enter image description here

I tried to fix this by making the xAxis.majorIntervalLength 3600, but that just makes the graph look like this:

enter image description here

The tick are stil there, but now they're just placed 3600 placed apart, if that makes sense. Here is my code:

CPTXYAxisSet *faxisSet = (CPTXYAxisSet *)self.graph.axisSet;

    faxisSet.xAxis.title = @"Time";
    faxisSet.xAxis.titleTextStyle = textStyle;
    faxisSet.xAxis.titleOffset = 30.0f;
    faxisSet.xAxis.axisLineStyle = axislineStyle;
    faxisSet.xAxis.majorTickLineStyle = axislineStyle;
    faxisSet.xAxis.minorTickLineStyle = axislineStyle;
    faxisSet.xAxis.labelTextStyle = textStyle;
    faxisSet.xAxis.labelOffset = 3.0f;
    faxisSet.xAxis.majorIntervalLength = CPTDecimalFromFloat(3600.0f);
    faxisSet.xAxis.minorTicksPerInterval = 1;
    faxisSet.xAxis.minorTickLength = 5.0f;
    faxisSet.xAxis.majorTickLength = 7.0f;
NSString *dats1 = @"16";
    NSDateFormatter *dateFormatter3 = [[[NSDateFormatter alloc] init] autorelease];
    [dateFormatter3 setDateStyle:NSDateFormatterMediumStyle];
    [dateFormatter3 setDateFormat:@"hh:mm:ss a"];
    CPTTimeFormatter *timeFormatter  =   [[CPTTimeFormatter alloc]initWithDateFormatter:dateFormatter3];
    timeFormatter.referenceDate =   [dateFormatter3 dateFromString:dats1];
    faxisSet.xAxis.labelFormatter    =   timeFormatter;

Basically, I would like to have every other tick mark read hours but I would like them to remain the same distance apart.

I'd appreciate any help, thanks!

Upvotes: 0

Views: 136

Answers (1)

Eric Skroch
Eric Skroch

Reputation: 27381

Check out the CPTCalendarFormatter. It formats dates by unit intervals (e.g., hours) rather than by a time value like CPTTimeFormatter.

Upvotes: 1

Related Questions