簡體   English   中英

如何通過圖表外的按鈕將Highchart圖表導出為PDF?

[英]How to export a Highchart chart to PDF thanks to a button outside the chart?

我想button outside a Highchart chart有一個button outside a Highchart chart ,用PDF export圖表。

  • 它是否存在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>

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 ?
    });
});

這是我想要的JsFiddle

這是一個有Wergeld解決方案的JsFiddle

請參閱API。 這將在exportChart 基本上這樣做:

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

查看Highcharts的導出屬性。 您需要將type設置為application/pdf

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM