-
Notifications
You must be signed in to change notification settings - Fork 0
/
chartme.php
24 lines (20 loc) · 920 Bytes
/
chartme.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?php
function chartme( $yparam, $title, $dataurl, $interval, $min=0, $max=100, $canvas, $w,$h, $col, $dur) {
echo '<h3>'.$title.'</h3>';
#calculate the miliseconds per pixel to cover the target duration (expressed in minutes)
$mpp = ($dur*60000)/$w;
echo '<canvas id="'.$canvas.'" width="'.$w.'" height="'.$h.'"></canvas>';
echo '<script>';
echo 'var '.$yparam.'= new SmoothieChart({millisPerPixel:'.$mpp.', minValue:'.$min.', maxValue:'.$max.'});';
echo $yparam.'.streamTo(document.getElementById("'.$canvas.'"),1000);';
echo 'var ds'.$yparam.'= new TimeSeries;';
echo 'setInterval(function(){';
echo '$.getJSON("'.$dataurl.'", function(data){';
echo 'var now = new Date().getTime();';
echo 'ds'.$yparam.'.append(now,data[1])';
echo '});';
echo '},'.$interval.');';
echo $yparam.'.addTimeSeries(ds'.$yparam.', {lineWidth:2,strokeStyle:"'.$col.'"})';
echo '</script>';
}
?>