Question

I have an issue with showing a range of dates on x-axis. This range contains dates as timestamp values: 1398172101, 1398176156, 1398181026, 1398196536, etc. Below code shows how I try to format the date to be human-readable

 NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
 [dateFormatter setDateFormat:@"hh:mm dd/MM/yy"];
 CPTTimeFormatter *timeFormatter = [[CPTTimeFormatter alloc] initWithDateFormatter:dateFormatter];
 timeFormatter.referenceDate = [NSDate dateWithTimeIntervalSince1970:0.0];
 x.labelFormatter = timeFormatter;

I'm not sure if I set right value for timeFormatter.referenceDate. I found a question on stackoverflow which describe same issue, but the right answer doesn't work for me. It tells to assing [NSDate dateWithTimeIntervalSince1970:0.0] to timeFormatter.referenceDate

Whats the mistake I did ? Thanks

Was it helpful?

Solution

Make sure the xRange of the plot space is set correctly. For example, to make a range enclosing the values listed in the question, do this:

NSTimeInterval minTime = 1398172101;
NSTimeInterval maxTime = 1398196536;
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(minTime)
                                                length:CPTDecimalFromDouble(maxTime - minTime)];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top