This example shows how to run a live chart with data retrieved from the server each second. Study the source code for details.

This is the content of the PHP file, live-server-data.php:

<?php 
// Set the JSON header
header("Content-type: text/json");
 
// The x value is the current JavaScript time, which is the Unix time multiplied by 1000.
$x = time() * 1000;
// The y value is a random number
$y = rand(0, 100);
 
// Create a PHP array and echo it as JSON
$ret = array($x, $y);
echo json_encode($ret);
?>