Core Plot在x-Axis上显示错误的日期

时间:2014-04-22 21:48:31

标签: ios objective-c ios7 core-plot

我在x轴上显示一系列日期时遇到问题。此范围包含日期作为时间戳值:1398172101,1398176156,1398181026,1398196536等。下面的代码显示了我如何设置日期格式为人类可读

 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;

我不确定我是否为timeFormatter.referenceDate设置了正确的值。我在stackoverflow上找到了一个描述相同问题的问题,但正确的答案并不适用于我。它告诉[NSDate dateWithTimeIntervalSince1970:0.0] timeFormatter.referenceDate

我做错了什么?感谢

1 个答案:

答案 0 :(得分:0)

确保绘图空间的xRange设置正确。例如,要创建一个包含问题中列出的值的范围,请执行以下操作:

NSTimeInterval minTime = 1398172101;
NSTimeInterval maxTime = 1398196536;
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(minTime)
                                                length:CPTDecimalFromDouble(maxTime - minTime)];