为什么 phantom 不能正确呈现页面?

Why phantom doesn't renders page correctly?

我正在尝试使用 phantomjs 将 html 渲染到 jpg

Phantom 完美呈现堆栈溢出站点,但不呈现我自己的 html 页面(显示饼图,由 js 生成)。

这里是幻影脚本:

var webPage = require('webpage');
var system = require('system');
var page = webPage.create();


page.viewportSize = { width: 1920, height: 1080 };
page.open(system.args[1], function start(status) {
  page.render('index.jpeg', {format: 'jpeg', quality: '100'});
  phantom.exit();
});

这里是输出 img:

如何修复渲染?

图表可能没有显示在图像中,因为屏幕截图是在打开页面后立即制作的。像这样尝试推迟截图一秒钟:

page.open(system.args[1], function start(status) {
  setTimeout(function(){
    page.render('index.jpeg', {format: 'jpeg', quality: '100'});
    phantom.exit();
  }, 1000);
});