PHP Classes
elePHPant
Icontem

File: chart1.tpl

Recommend this page to a friend!
  Classes of Gianluca Zanferrari  >  PHP Graph Real Time  >  chart1.tpl  >  Download  
File: chart1.tpl
Role: Auxiliary data
Content type: text/plain
Description: template
Class: PHP Graph Real Time
Display graphs of machine usage in real time
Author: By
Last change:
Date: 4 years ago
Size: 2,470 bytes
 

 

Contents

Class file image Download
<script>
$(function () {
    $(document).ready(function () {
	
        Highcharts.setOptions({
            global: {
                useUTC: false
            }
        });

        $('#container_@container@').highcharts({
            chart: {
                type: 'spline',
                animation: Highcharts.svg, // don't animate in old IE
                marginRight: 10,
                events: {
                    load: function () {

                        // set up the updating of the chart each second
                        var series = this.series[0];
                        setInterval(function () {
                            var x = (new Date()).getTime(), // current time
                            y = Math.random();
							$.get( "serverdata.php?monitor=@monitor@", function( data ) {
								series.addPoint([x, data*1], true, true);
								$("#value_@container@").html("<h3>"+data*1+" @entity@</h3>");
							});
                        }, @interval@);
                    }
                }
            },
            title: {
                text: '@monitor_title@'
            },
            xAxis: {
                type: 'datetime',
                tickPixelInterval: 150
            },
            yAxis: {
                title: {
                    text: 'Value'
                },
                plotLines: [{
                    value: 0,
                    width: 1,
                    color: '#808080'
                }]
            },
            tooltip: {
                formatter: function () {
                    return '<b>' + this.series.name + '</b><br/>' +
                        Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.x) + '<br/>' +
                        Highcharts.numberFormat(this.y, 2);
                }
            },
            legend: {
                enabled: false
            },
            exporting: {
                enabled: false
            },
            series: [{
                name: 'Data',
                data: (function () {
						// generate an array of random data
						var data = [],
                        time = (new Date()).getTime(),
                        i;
						for (i = -50; i <= 0; i += 1) {
							data.push({
								x: time + i * 10000,
								y: 0
							});
						}
                    return data;
                }())
            }]
        });
    });
});
</script>