简体   繁体   English

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

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

I would like to have a button outside a Highchart chart that export the chart in PDF . 我想button outside a Highchart chart有一个button outside a Highchart chart ,用PDF export图表。

  • Does it exist a Highchart method to do that ? 它是否存在Highchart方法?
  • Does an ajax call is mandatory ? ajax呼叫是强制性的吗?

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

Here is a JsFiddle of what I would like. 这是我想要的JsFiddle

Here is a JsFiddle with the solution of wergeld . 这是一个有Wergeld解决方案的JsFiddle

See the API. 请参阅API。 This is covered here under exportChart . 这将在exportChart Essentially do this: 基本上这样做:

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

Check out the exporting properties for Highcharts. 查看Highcharts的导出属性。 You will want to set type to application/pdf . 您需要将type设置为application/pdf

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM