Highcharts Demo

author(s): Torstein Hønsi

HTML

<script src="http://code.highcharts.com/stock/highstock.js"></script>
<script src="http://code.highcharts.com/stock/modules/exporting.js"></script>

<div id="container" style="height: 400px; min-width: 310px"></div>

JavaScript

$(function () {

    Highcharts.setOptions({
        global : {
            useUTC : false
        }
    });
    
    function requestData() {
        $.ajax({
            url: 'http://www.highcharts.com/studies/live-server-data.php',
            success: function(point) {
                var series = window.chart.series[0],
                    shift = series.data.length > 20; // shift if the series is 
                                                     // longer than 20
    
                // add the point
                window.chart.series[0].addPoint(point, true, shift);
                
                // call it again after one second
                setTimeout(requestData, 1000);    
            },
            cache: false
        });
    }

    // Create the chart
    window.chart = new Highcharts.Chart({
        chart: {
            renderTo: 'container',
            events : {
                load : requestData
            }
        },

        rangeSelector: {
            buttons: [{
                count: 1,
                type: 'minute',
                text: '1M'
            }, {
                count: 5,
                type: 'minute',
                text: '5M'
            }, {
                type: 'all',
                text: 'All'
            }],
            inputEnabled: false,
            selected: 0
        },

        title : {
            text : 'Live random data'
        },

        exporting: {
            enabled: false
        },

        series : [{
            name : 'Random data',
            data : (function () {
                // generate an array of random data
                var data = [], time = (new Date()).getTime(), i;

                for (i = -999; i <= 0; i += 1) {
                    data.push([
                        time + i * 1000,
                        Math.round(Math.random() * 100)
                    ]);
                }
                return data;
            }())
        }]
    });

});