This chart shows a measurement for downloads. It uses template
"demo_meter.php". This template adds two buttons to trigger the measurement by
calling a small javascript which issues a download request, calculates the timings and posts
the result.
The event script (see variable $event_script), which adds an events listener, catches the post and updates the meter chart.
Code of the javascript ("demo.js") is stored in RGraph's javascript library.
<?php
include_once "environment.php";
use phpRGraph\rgraph_chart;
use phpRGraph\rgraph_options;
$template = "demo_meter.php";
$id = "cvs";
$draw_option = "draw();";
$width = "350";
$height = "350";
$tmp = explode("RGraph", $_SERVER['PHP_SELF']);
$host = $_SERVER['SERVER_NAME'] . $tmp[0];
if ($host == "localhost" . $tmp[0])
{
$max = 2500;
$red = 0;
$yellow = 400;
$green = 800;
}
else
{
$max = 100;
$red = 0;
$yellow = 16;
$green = 40;
}
$chart = new rgraph_chart("cvs", null, "Gauge");
$chart->set_min(0);
$chart->set_max($max);
$chart->set_value(0);
$options = new rgraph_options("gauge.ini");
$options->set_option("titleTop", "Your Download Speed");
$options->set_option("titleTopSubtitle", "megabits per second");
$options->set_option("labelsValueUnitsPost", " Mbps");
$options->set_option("radius",140);
$options->set_option("max",$max);
$options->set_option("colorsRanges",array( array(0,$yellow, 'rgba(255,0,0,0.6)'),array($yellow, $green,'yellow'),array($green, $max, 'rgba(0,255,0,0.6)' )));
$draw_option .= $options->getResponsiveFunction(array(0.3,990,1200, $width, $height));
$chart->set_options($options);
$rgraph_json = $chart->toPrettyString();
$event_script = $chart->getEventScript("meter_event.js");
$chart_script = "";
include_once ($templates . $template);
?>