Download Highchart as PNG - V1

by ideazgeni

HTML

<script src="http://code.highcharts.com/4.0.4/highcharts.js"></script>
<script src="http://code.highcharts.com/4.0.4/modules/exporting.js"></script>
<div id='container'></div>
<button id='save_btn'>Save Chart</button>

CSS

#container {
    max-width: 800px;
    height: 400px;
    margin: 1em auto;
}

JavaScript

EXPORT_WIDTH = 1000;

function save_chart(chart, filename) {
    var render_width = EXPORT_WIDTH;
    var render_height = render_width * chart.chartHeight / chart.chartWidth

    var svg = chart.getSVG({
        exporting: {
            sourceWidth: chart.chartWidth,
            sourceHeight: chart.chartHeight
        }
    });

    
    
    
}

function download(data, filename) {
    var a = document.createElement('a');
    a.download = filename;
    a.href = data
    document.body.appendChild(a);
    a.click();
    a.remove();
}


$(function() {

    $('#container').highcharts({

        exporting: {
            enabled: false
        },

        title: {
            text: 'Client-Side Download Example'
        },

        subtitle: {
            text: 'Click "Save Chart" to download chart as PNG'
        },

        chart: {
            type: 'area'
        },

        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]
        }]

    });
    
    $('#save_btn').click(function() {
        save_chart($('#container').highcharts(), 'chart');
    });

});