I am trying to export a div that contains a Chart.js chart as an Iamge. All elements are displayed perfectly fine, however, the Chart.js canvas just doesn't get rendered.
I am calling my export function in the callback of the onAnimationComplete option in my chart, so the export can't happen before the chart is fully built.
Here is how my html2canvas and download functions look:
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');
}});
}
Can anyone tell me if it is even possible to export Chart.js charts with html2canvas and if so, how? I also tried the toDataURL() function on the chart canvas but it only returns the data URL for a tranparent png.
Yes! It is possible to export (save as image) chart (created with ChartJS) using html2canvas.
HERE IS HOW :
PS: Needless to say but obviously, this is just an example, you need to adopt this accordingly to your project.