javascript - 将 Chartist 图表导出为 pdf 文档 (jspdf)

标签 javascript pdf jspdf chartist.js

我现在的情况是需要使用 jspdf 将图表输出到 javascript 生成的 pdf 文档中。

我想转换我网站上显示的图表。
我为此使用 Chartist。

有什么办法可以做到这一点吗?

最佳答案

您可以查看 jsPDF 的 addHTML 函数,它应该为您提供 Canvas 的干净副本

const pdf = new jsPDF('p','pt','a4')
const chartistChart = document.getElementById('your-chartist-chart')
const previewPane = document.getElementById('preview-pane')

// addHTML is marked as deprecated, see links below for further information
pdf.addHTML(chartistChart, function() {
    // Get the output pdf data URI
    const outputString = pdf.output('datauristring')
    // Changes the src to new data URI
    previewPane.attr('src', outputString)
})

关于javascript - 将 Chartist 图表导出为 pdf 文档 (jspdf),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31425244/

相关文章:

r - 如何在 R 中启动新的图形窗口和/或图形页面

javascript - 使用 doc.output() 的问题 - jsPDF

javascript - 在不转换为本地时区的情况下在 Javascript 中格式化日期

javascript - jQuery 告诉我某些东西不在数组中

ios - 带有选项字典崩溃应用程序的 UIGraphicsBeginPDFContextToFile

windows - 在 Windows 上使用 Chromium 查看 PDF

javascript - jsPDF AutoTable rowspan/colspan 来自 HTML 表

javascript - 将 html 导出为多页 pdf

javascript - 将对象追加到 DOM,缓冲事件直到下一个刻度?

javascript - 无法通过单击调用函数参数