简体   繁体   English

将图表从 html 导出为 pdf

[英]export graph from html to pdf

this my graph enter image description here这是我的图在这里输入图片描述

this javascript这个javascript



        /* export to pdf */
        function generatePDF() {
            var pdf = new jsPDF();
            var elementHTML = document.getElementById("line_top_x").innerHTML;
            var specialElementHandlers = {
                '#elementH': function (element, renderer) {
                    return true;
                }
            };
            pdf.fromHTML(elementHTML, 15, 15, {
                'width': 170,
                'elementHandlers': specialElementHandlers
            });
            pdf.save('line_top_x.pdf');
        }
        /* export to pdf end */
  

This HTML id is line_ top _x and has the onclick action of generatepdf().这个 HTML id 是line_top_x并且有 generatepdf() 的 onclick 动作。 funtion功能

<div>
    <div id="line_top_x"></div>
    <button onclick="generatePDF()">Export to PDF</button>
</div>

this result enter image description here这个结果在这里输入图像描述

it export just text but don't show graph它只导出文本但不显示图形

i want to export all detail to pdf我想将所有细节导出为 pdf

this code my graph这个代码我的图表

 google.charts.load('current', { 'packages': ['line'] }); google.charts.setOnLoadCallback(drawChart); function drawChart() { var data = new google.visualization.DataTable(); data.addColumn('number', 'Day'); data.addColumn('number', 'Guardians of the Galaxy'); data.addColumn('number', 'The Avengers'); data.addColumn('number', 'Transformers: Age of Extinction'); data.addRows([ [1, 37.8, 80.8, 41.8], [2, 30.9, 69.5, 32.4], [3, 25.4, 57, 25.7], [4, 11.7, 18.8, 10.5], [5, 11.9, 17.6, 10.4], [6, 8.8, 13.6, 7.7], [7, 7.6, 12.3, 9.6], [8, 12.3, 29.2, 10.6], [9, 16.9, 42.9, 14.8], [10, 12.8, 30.9, 11.6], [11, 5.3, 7.9, 4.7], [12, 6.6, 8.4, 5.2], [13, 4.8, 6.3, 3.6], [14, 4.2, 6.2, 3.4] ]); var options = { chart: { title: 'Box Office Earnings in First Two Weeks of Opening', subtitle: 'in millions of dollars (USD)' }, width: 900, height: 500, axes: { x: { 0: { side: 'top' } } } }; var chart = new google.charts.Line(document.getElementById('line_top_x')); chart.draw(data, google.charts.Line.convertOptions(options)); }

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

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