chart.js - Chart.js 不适用于 PDF 的 Pug 和 Node
问题描述
我正在尝试使用Chart.js
,和在 PDF 文件中创建折线图Node
,但它不起作用。Pug
Headless chrome (html-pdf-chrome)
呈现的 HTML 直接在浏览器中工作,但生成的 PDF 是空白的。添加超时与 completionTrigger 没有区别。
我想知道是否有可能做到这一点,如果可以,我哪里出错了?
节点文件:
const pug = require('pug');
const htmlPdf = require('html-pdf-chrome');
async function createPDF() {
const html = pug.renderFile('template.pug', {})
const options = {
port: 9222,
completionTrigger: new htmlPdf.CompletionTrigger.Timer(5000),
};
htmlPdf.create(html, options).then((pdf) => pdf.toFile('output.pdf'));
}
createPDF();
帕格模板:
doctype html
html
head
meta(charset="utf-8")
title test
script(type="text/javascript", src='chart.js')//chart.js lib
script(type="text/javascript", src='scripts.js')
body
canvas#myChart(width='200' height='100' style='border:1px solid #000000;')
脚本文件:
window.onload = function () {
const ctx = document.getElementById('myChart').getContext('2d');
const chart = new Chart(ctx, {
type: 'line',
data: {
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
datasets: [{
label: 'My First dataset',
backgroundColor: 'rgb(255, 99, 132)',
borderColor: 'rgb(255, 99, 132)',
data: [0, 10, 5, 2, 20, 30, 45]
}]
},
options: {}
});
};
解决方案
推荐阅读
- wordpress - 如何限制用户在 24 小时内仅登录一次?在 WordPress 中
- lldb - lldb 是否可以在断点检查已写入文件的内容或它生成/使用的 IPC 机制中的数据?
- sharepoint - 如何使用powershell脚本从sharepoint中的自定义列表中删除10000个项目
- python - 什么是更改大文件的有效方法
- java - Java 程序 - 使用 For 循环的插入排序
- c# - C# 表达式:数据表的 SQL/LINQ 动态排序
- angular - 通过 ngModel 将绑定值从 Input 元素传递给 Model
- javascript - 获取访问者的纬度和经度并显示它的谷歌地图
- python - 如何使用 LIKE 子句转义 pymysql 中的 % 和 \ 符号?
- mysql - 使用模糊匹配将 2 个 MySQL 表合并为一个