【发布时间】:2018-02-09 07:22:09
【问题描述】:
我正在尝试将包含 Chart.js 图表的 div 导出为 Iamge。所有元素都显示得非常好,但是 Chart.js 画布没有被渲染。
我在图表中 onAnimationComplete 选项的回调中调用我的导出函数,因此在图表完全构建之前无法进行导出。
这是我的 html2canvas 和下载功能的外观:
download() {
this.dl.download = this.fileName;
this.dl.click();
}
loadDataUrl($node) {
this.hideUnwantedElements();
html2canvas($node, {
background: '#ffffff',
scale: 4,
proxy: 'proxy-for-cors-images',
onrendered: (canvas) => {
this.showElements();
this.dl.href = canvas.toDataURL('image/jpeg');
}});
}
谁能告诉我是否可以使用 html2canvas 导出 Chart.js 图表,如果可以,怎么做? 我还在图表画布上尝试了 toDataURL() 函数,但它只返回透明 png 的数据 URL。
【问题讨论】:
标签: javascript charts chart.js html2canvas todataurl