我想添加两个图像以形成单个图像并保存。在尝试保存时,它要么保存单个图像。所以我试图将图像添加到单个图像中,如下所示:
function getImgData(chartContainer) {
var chartArea = chartContainer.getElementsByTagName('svg')[0].parentNode;
var chartArea1 = chartContainer.getElementsByTagName('svg')[1].parentNode;
var svg = chartArea.innerHTML + chartArea1.innerHTML;
var doc = chartContainer.ownerDocument;
var canvas = doc.createElement('canvas');
var cwidth = chartArea.offsetWidth + chartArea1.offsetWidth;
var cheight = chartArea.offsetHeight + chartArea1.offsetHeight;
canvas.setAttribute('width',cwidth );
canvas.setAttribute('height',cheight );
canvas.setAttribute(
'style',
'position: absolute; ' +
'top: ' + (-cheight* 2) + 'px;' +
'left: ' + (-cwidth * 2) + 'px;');
doc.body.appendChild(canvas);
canvg(canvas, svg);
var imgData = canvas.toDataURL("image/png");
canvas.parentNode.removeChild(canvas);
return imgData;
}
但它没有加起来,只显示第一张图片。请建议。