【发布时间】:2015-12-12 16:14:12
【问题描述】:
我想生成一个图表以添加到电子邮件中。我正在考虑使用 PhantomJS 来做到这一点。我正在使用 2.0 版的 PhantomJS。我想加载 d3.js(在 cloudfare 上)和 c3.js(在本地 js 文件中)。我在这里遗漏了一些东西。当我使用 PhantomJS 运行脚本时,它会在窗口对象上返回 d3 作为 undefined。
我下面的代码不起作用:
var page = require('webpage').create();
var fs = require('fs');
page.viewportSize = { width: 400, height : 400 };
page.content = '<html><body><canvas id="surface"></canvas> <button>Hello world</button> </body></html>';
page.includeJs("https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.min.js");
var c3_js = "./c3.min.js";
page.includeJs(c3_js);
page.onLoadFinished = function(status) {
var c3 = page.evaluate(function() {
return window;
});
console.log(c3.d3);
page.render('test.png');
phantom.exit();
};
【问题讨论】:
标签: javascript phantomjs