Core-Plot:x-Axis上的错误日期

Sim*_*mon 3 xcode nsdateformatter core-plot

根据不同的教程,我使用Core-Plot成功创建了一个散点图.现在,在X轴上设置日期我得到了完全错误的日期.我的图形源是一个包含字典的数组.在字典的每个记录中,字典的第一个键是unix时间戳,第二个键是绘制的值.它看起来像这样:

    (
            {
        0 = 1334152500;
        1 = 0;
    },
            {
        0 = 1334152800;
        1 = 0;
    },
            {
        0 = 1334153100;
        1 = 0;
    },
Run Code Online (Sandbox Code Playgroud)

AFAIK Core-Plot需要一个开始日期和一个步骤.在这种情况下,开始日期是1334152500(2012年4月11日星期三,格林尼治标准时间13:55:00),步骤是300秒.每隔300秒就会出现一个新值.现在我用来绘制X轴的代码:

// this string contains the first UNIX Timestamp registered
NSString *tstamp_start = [NSString stringWithFormat:@"%@", [[[self.graphData  objectForKey:@"1"] objectAtIndex:0] objectForKey:@"0"]];
NSDate *refDate = [NSDate dateWithTimeIntervalSince1970:[tstamp_start doubleValue]];

// definition of the graph skipped...

CPTXYAxisSet *axisSet = (CPTXYAxisSet *)self.graph.axisSet;
// tInterval is previous set to 300 - float.
// here I should set the Interval between every value on graph...
axisSet.xAxis.majorIntervalLength = CPTDecimalFromFloat(tInterval);
axisSet.xAxis.axisLineStyle = axisLineStyle;
axisSet.xAxis.majorTickLineStyle = axisLineStyle;
axisSet.xAxis.minorTickLineStyle = axisLineStyle;
axisSet.xAxis.labelTextStyle = textStyle;
axisSet.xAxis.labelOffset = 3.0f;
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"dd/MM/yyyy hh:mma"];
CPTTimeFormatter *timeFormatter = [[CPTTimeFormatter alloc] initWithDateFormatter:dateFormatter];
timeFormatter.referenceDate = refDate;
axisSet.xAxis.labelFormatter = timeFormatter;
axisSet.xAxis.labelingPolicy = CPTAxisLabelingPolicyAutomatic;
axisSet.xAxis.orthogonalCoordinateDecimal = CPTDecimalFromFloat(yAxisMin);
(...)
Run Code Online (Sandbox Code Playgroud)

该行正确显示,但在X轴上我正在读取值/标签,如:'22/07/2054 06:35 AM'.2054年?不考虑时区(本地+2,unix +0)和CPTAxisLabelingPolicyAutomatic,至少我应该读取13:55到现在当天的日期.我错过了什么?

非常感谢!

西蒙

Eri*_*och 5

referenceDate是偏移量格式化当施加到每个数据点.因此,第一个数据点的值加倍.您需要调整参考日期或将数据值更改为从0开始.

NSDate *refDate = [NSDate dateWithTimeIntervalSince1970:0.0];
Run Code Online (Sandbox Code Playgroud)