user1691024
user1691024

Reputation: 199

Replace Timestamp with PHP variables in Flot Graph

Hi I have a template which uses a flot graph, which uses timestamps to plot the data on the graph as displayed below.

var d2 = [
 [1364511661, 2],[1364630461, 20],[1364731261, 28],[1364824861, 37],[1364925661, 76],[1367190061, 88]
     ];

what i am trying to do is replace the timestamps with timestamps taken from the MYSQL database, however I can not seem to get it to work. below is my code.

var d2 = [ 
            <?php while($row = mysql_fetch_array($result))
            ?>

            <?php { ?> [<?php echo $row['timestamp']; ?>,25 ], <?php } ?>

            ];

Any suggestions would be appreciated, thanks

Upvotes: 1

Views: 592

Answers (1)

chrki
chrki

Reputation: 6323

Flot requires that you provide timestamps in milliseconds, that means you have to multiply your PHP timestamps by 1000. (Source)

If you are using the datetime format for your database timestamp column, that will result in something like "2013-04-28 16:15" and NOT a unix timestamp. You will have to convert it using strtotime first, then multiply by 1000 again. You have to use flot's API functions afterwards to make them human readable again.

Upvotes: 1

Related Questions