Nach verschiedenen Tutorials habe ich erfolgreich ein Streudiagramm mit Core-Plot erstellt. Jetzt, Datum auf X-Achse setzend, erhalte ich völlig falsche Daten. Die Quelle meines Diagramms ist ein Array mit einem Wörterbuch. In jedem Datensatz des Wörterbuchs ist der erste Schlüssel des Wörterbuchs ein Unix-Zeitstempel und der zweite Schlüssel der zu zeichnende Wert. Es sieht so aus:Core-Plot: Falsches Datum auf x-Achse
(
{
0 = 1334152500;
1 = 0;
},
{
0 = 1334152800;
1 = 0;
},
{
0 = 1334153100;
1 = 0;
},
AFAIK Core-Plot Benötigt ein Startdatum und einen Schritt. In diesem Fall ist das Startdatum 1334152500 (Mi, 11 Apr 2012 13:55:00 GMT) und der Schritt ist 300 Sekunden. Alle 300 Sekunden ist ein neuer Wert vorhanden. Jetzt ist der Code, den ich verwende, um die X-Achse zu zeichnen:
// 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);
(...)
Die Linie korrekt angezeigt wird, aber auf X-Achse ich Werte/Labels wie Lese: '22/07/2054 06.35‘. Jahr 2054? Ohne Berücksichtigung der Zeitzone (local +2, unix +0) und CPTAxisLabelingPolicyAutomatic sollte ich zumindest ein Datum zwischen 13:55 und jetzt am aktuellen Tag lesen. Was ich vermisse?
Vielen Dank!
Simon
Vielen Dank, das war definitiv mein Fehler :) – Simon