views:

96

answers:

2

I have a Core-Plot scatter plot that seems to be working great. The x axis shows date/time, the y axis a value from 0-500. I set up the x axis as follows:

    plotSpace.xRange = [CPPlotRange plotRangeWithLocation:
                        CPDecimalFromFloat(maxTime - 2*60*60*24) 
                         length:CPDecimalFromFloat(2.5*60*60*24)];
    plotSpace.globalXRange = [CPPlotRange plotRangeWithLocation:
                        CPDecimalFromFloat(minTime - 1.5*60*60*24) 
                         length:CPDecimalFromFloat(maxTime - minTime + 2*60*60*24)];

    x.majorIntervalLength = CPDecimalFromFloat(12*60*60);
    x.minorTicksPerInterval = 0;
    NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
    [dateFormatter setDateFormat:@"M/d H:mm a"];
    CPTimeFormatter *timeFormatter = [[[CPTimeFormatter alloc]
                initWithDateFormatter:dateFormatter] autorelease];
    timeFormatter.referenceDate = [NSDate
                dateWithTimeIntervalSinceReferenceDate:0];
    x.labelFormatter = timeFormatter;

My x-axis points are plotted as follows:

-(NSNumber *)numberForPlot:(CPPlot *)plot 
                     field:(NSUInteger)fieldEnum 
               recordIndex:(NSUInteger)index 
{
    if(fieldEnum == CPScatterPlotFieldX) { 
        return [NSNumber numberWithDouble:[[(Entry *)
            [datapoints objectAtIndex:index] datetime]
            timeIntervalSinceReferenceDate]]; 
    }

As far as I can tell, everything is being plotted accurately. BUT, for some reason, the ticks occur at 5 AM and 5 PM, rather than noon and midnight as I would prefer.

I've tried everything -- changing the xRange and globalXRange location and length, altering my dataset, etc. But every time the labels reappear at 5 AM and 5 PM. Can you help? Thanks!

A: 

5 hours sounds like a time zone problem. Try setting the timeZone property on your dateFormatter to [NSDateFormatter timeZoneForSecondsFromGMT:0].

Eric Skroch
Genius! This corrected all the ticks to midnight and noon: `[dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];`Then in my numberForPlot method, I adjusted the time as follows:double time = [[(Entry *)[datapoints objectAtIndex:index] datetime] timeIntervalSinceReferenceDate];return [NSNumber numberWithDouble:(time + [[NSTimeZone localTimeZone] secondsFromGMT])];
ed94133
A: 

Thanks for giving valuable information regarding label formating,Everything works fine.But How can we customize time differentiate between tickLocations,Suppose I want to show labels for every hour,then how can I manipulate the coding....Currently it is showing for every 10Hr.21Min labelling.Could you help me to labelling for my graph.

Srinivas G