highcharts

Is possible to export programmatically a highcharts chart?


I would like to make some reports and mail them out, using the data that I have on the web pages that my server display.

Is there a way via code, to export the graph; so I can attach it in a mail? I see that is possible to save the graph as image, using the mouse, but I can't see how you can actually go via code and create a version of the graph as image.


Solution

  • Yes, it is possible.

    As you've noted it requires the export module, which is included by also having:

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

    The functionality you are looking for is the chart.exportChart function. It allows you to:

    Submit an SVG version of the chart to a server along with some parameters for conversion.

    Which can simply mean saving it through a button click, as shown in this simple JFiddle demo. The functionality of the button is then:

    $('#button').click(function() {
        var chart = $('#container').highcharts();
        chart.exportChart();
    });