I would like to have a button outside a Highchart chart that export the chart in PDF.
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
<div id="container" style="height: 400px; margin-top: 1em"></div>
<button id="export2pdf">Export to PDF</button>
$(function () {
    window.chart = new Highcharts.Chart({
        chart: {renderTo : 'container'},
        title: {
            text: 'Exporting module is loaded but buttons are disabled'
        },
        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]        
        }],
        exporting: {
            enabled: true
        }
    });
    $("#export2pdf").click(function(){
        // Export method ?
        // Ajax call ?
    });
});
Here is a JsFiddle of what I would like.
Here is a JsFiddle with the solution of wergeld.
See the API. This is covered here under exportChart.
Essentially do this:
var chart = $('#container').highcharts();
chart.exportChart({
    type: 'application/pdf',
    filename: 'my-pdf'
});
Check out the exporting properties for Highcharts. You will want to set type to application/pdf.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With