Highcharts Demo

author(s): Torstein Hønsi

by Gert Vaartjes

HTML

<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
<script src="https://rawgit.com/douglascrockford/JSON-js/master/json2.js"></script>
<div id="container"></div>

JavaScript

$(function () {
    /**
     * Check for SVG and VML support. If none is present, send the entire chart config to the 
     * Highcharts export server and display a generated image of the chart.
     */
    Highcharts.wrap(Highcharts.Chart.prototype, 'init', function (proceed, options, callback) {

        if (Highcharts.svg || Highcharts.vml) {
            proceed.call(this, options, callback);
        } else {
            renderTo = options.chart.renderTo;
            delete options.chart.renderTo; // prevent cyclic json in case of DOM element

            // Do the AJAX call
            $.ajax({
                dataType: 'jsonp',
                data: {
                    jsonp: true,
                    type: 'png',
                    width: options.chart.width,
                    options: JSON.stringify(options)
                },
                url: 'http://export.highcharts.com/',
                success: function (data) {
                    $('<img>').attr({
                        src: 'http://export.highcharts.com/' + data
                    })
                    .appendTo(renderTo);
                }
            });
        }

    });

    $('#container').highcharts({

        chart: {
            width: 600,
            height: 400
        },

        xAxis: {
            categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
                'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
        },

        series: [{
            data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
        }]

    });



});