如何通过图表外的按钮将Highchart图表导出为PDF?

kma*_*mas 11 javascript pdf jquery charts highcharts

我想有一个button outside a Highchart chartexport在图表PDF.

  • 它是否存在Highchart方法?
  • ajax呼叫是强制性的吗?

HTML:

<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>
Run Code Online (Sandbox Code Playgroud)

Javascript:

$(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 ?
    });
});
Run Code Online (Sandbox Code Playgroud)

这是我想要的JsFiddle.

这是一个有Wergeld解决方案的JsFiddle.

wer*_*eld 21

请参阅API.这将在下面介绍exportChart.基本上这样做:

var chart = $('#container').highcharts();
chart.exportChart({
    type: 'application/pdf',
    filename: 'my-pdf'
});
Run Code Online (Sandbox Code Playgroud)