This is basic demo of using Web Workers (which are child threads) to generate a random value which is posted back to the main thread (this page). The value is then used to update the Gauge. To make a useful example you could use the child thread in conjunction with Web Sockets to retieve (for example) load values from your server(s). Also, to retrieve data from your server you may find it easier and less involved to use AJAX.
<?php
include_once "environment.php";
use phpRGraph\rgraph_chart;
use phpRGraph\rgraph_options;
// rgraph chart
$template = "default.php";
$id = "cvs";
$draw_option = "draw();";
$width = "500";
$height = "350";
$chart = new rgraph_chart("cvs", $data, "Gauge");
$chart->set_min(0);
$chart->set_max(1);
$chart->set_value(0);
$options = new rgraph_options();
$options->set_option("scaleDecimals", 1);
$chart->set_options($options);
$rgraph_json = $chart->toString();
$event_script = "
/**
* Create the worker child thread. The code that is used as the
child thread is held in the libraries/basic-web-workers.js file.
*/
var worker = new Worker('libraries/basic-web-workers.js');
/**
* The message event is used to listen for messages from the worker thread.
When it sends a message to the main thread (ie the main page)
the message event is fired and this function runs.
It simply updates the Gauge using the Grow effect.
*/
worker.addEventListener('message', function (e)
{
// The data/message that is returned from the worker is a string - so
// it must be converted to a number
var value = (Number(e.data) * 0.2) + 0.4;
chart.value = value;
chart.grow();
}, false);";
$chart_script = "";
include_once ($templates . $template);
?>