Menu

X axis time format incorrect

Gromlok
2010-04-07
2012-09-07
  • Gromlok

    Gromlok - 2010-04-07

    2010-04-07 02:58:22 EDT

    Hello:

    I'm doing a time line of a chat. In the X axis I put the seconds of a chat
    occurrence (I change the HH:MM:SS from the chat in seconds), but when I plot
    the Chart it star at 09:00:00! So, If I put "3600 seconds", that would be
    "01:00:00", I get "09:00:00"!!! (see code above)

    I don't know why. I set the "$plot->SetXLabelType('time', '%H:%M:%S')".

    Here is my code:

    SetImageBorderType('plain'); $plot->SetPlotType('squared'); $plot->SetDataType('data-data'); $plot->SetDataValues($data); # Set title of Chart, and so for X, Y axis. $plot->SetTitle('Time Chart (Chat)'); $plot->SetXTitle('Time'); $plot->SetYTitle('# of Chat'); # Set data type of X: Time $plot->SetXLabelType('time', '%H:%M:%S'); $plot->SetXTimeFormat('%H:%M:%S'); # Set Legend //$plot->SetLegend(array('Chocolates', 'Mints', 'Hard Candy', 'Sugar-Free')); # Make the lines a bit wider: $plot->SetLineWidths(2); # Turn on the X grid (Y grid is on by default): $plot->SetDrawXGrid(True); # Use exactly this data range: //$plot->SetPlotAreaWorld(0, 0, 100, 40); $plot->DrawGraph(); ?>

    Is just an example. Maybe is something of the local time of my PC or
    something? I need the "pure" time!

    Thank you very much.

     
  • lbayuk

    lbayuk - 2010-04-08

    (Minor point first: If you use SetXLabelType() to set a time format, don't
    also use SetXTimeFormat. There is no harm but it is redundant.)

    The date/time values are in seconds since an epoch. So 3600 doesn't mean 1
    hour, it means 1 hour past midnight UTC on the epoch date, in local time. I
    can see this if I change the format to %Y-%m-%d %H:%M:%S (I also have to
    change them to 90 degrees so I can read them). The first tick mark is at
    1969-12-31 20:00:00 (local time, would be 1970-01-01 00:00:00 + 1 hour UTC).

    So what you need to do to make relative times is to pick a base date/time and
    use that as offset. Something like this:

    $base_time = mktime(0, 0, 0, 1, 1, 2000); // 2000-01-01 local midnight
    $data = array(
    array('', 3600 + $base_time, 6),
    array('', 3660 + $base_time, 7),
    etc.
    
     
  • Gromlok

    Gromlok - 2010-04-12

    Thank you very much. It worked, now I have a consistent time in the axis.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.