将Highchart版本从6.0.7升级到8.0.4后,我面临图像剪切问题

时间:2020-05-12 07:20:33

标签: highcharts phantomjs

我正在使用Highchart 6.0.7版本,并将其更新为8.0.4。我正在使用通过Highchart Converte JS的幻影js生成图像。以前,它是在升级了面对图像切割问题的较新版本之后才工作的。

图像宽度正在裁切。我同时传递了Exportortingchart的高度宽度值。

1 个答案:

答案 0 :(得分:0)

从Highcharts版本7.0.2切换到8.0.4时,我遇到了同样的问题。图像的右侧被剪切。我通过修补highcharts-convert.js来始终设置viewportSize而不是仅调整PDF的viewportSize来解决了这个问题。

在highcharts-convert.js中,这是原始代码

if (outType === 'pdf') {
    // redefine the viewport
    page.viewportSize = { width: clipwidth, height: clipheight };

    // simulate zooming to get the right zoomFactor. Using page.zoomFactor doesn't work anymore, see issue here https://github.com/ariya/phantomjs/issues/12685
    page.evaluate(function (zoom) {
        document.getElementsByTagName('body')[0].style.zoom = zoom;
    }, page.zoomFactor);

    page.paperSize = { width: clipwidth * dpiCorrection, height: clipheight * dpiCorrection };
}

我将代码更改为此

// redefine the viewport
page.viewportSize = { width: clipwidth, height: clipheight };

if (outType === 'pdf') {
    //// redefine the viewport
    //page.viewportSize = { width: clipwidth, height: clipheight};

    // simulate zooming to get the right zoomFactor. Using page.zoomFactor doesn't work anymore, see issue here https://github.com/ariya/phantomjs/issues/12685
    page.evaluate(function (zoom) {
        document.getElementsByTagName('body')[0].style.zoom = zoom;
    }, page.zoomFactor);

    page.paperSize = { width: clipwidth * dpiCorrection, height: clipheight * dpiCorrection };
}

我希望这对其他人一样对我也一样。