提问人:Mayuna 提问时间:7/21/2023 更新时间:7/21/2023 访问量:71
使用 phantomjs 渲染chart.js会导致 ReferenceError: Can't find variable: Chart
Rendering chart.js using phantomjs results in ReferenceError: Can't find variable: Chart
问:
我正在尝试使用 phantomjs 渲染chart.js图表。但是,在运行 phantomjs 时,我收到错误 .在浏览器中打开我正在尝试呈现的 HTML 文件不会出现此问题。ReferenceError: Can't find variable: Chart
- PhantomJS 的脚本文件:
page = require('webpage').create();
page.open('file:///path/to/file.html', function()
{
page.viewportSize = {
width: 850,
height: 300
};
page.render('graph.png');
phantom.exit(0);
});
file.html
:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
</head>
<body>
<div>
<canvas id="myChart"></canvas>
</div>
<script>
const ctx = document.getElementById('myChart');
new Chart(ctx, {
type: 'bar',
data: {
labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
datasets: [{
label: '# of Votes',
data: [12, 19, 3, 5, 2, 3],
borderWidth: 1
}]
},
options: {
scales: {
y: {
beginAtZero: true
}
}
}
});
</script>
</body>
</html>
我用来运行 PhantomJS 的命令:.我正在使用PhantomJS版本。phantomjs.exe script.js
2.1.1
有什么我忘记设置或配置了吗?
答: 暂无答案
评论
file
chart.js
file.html
phantom.js
chart.js
phantomjs
chart.js
phantomjs