1👍
This is a bit more complicated than simply what image format is being used.
You need to explicitly set the canvas background to white. But exactly when to do this can be tricky. Please see my answer in a similar question.
- [Chartjs]-Chart.js: bar chart first bar and last bar not displaying in full
- [Chartjs]-How to vary the thickness of doughnut chart, using ChartJs.?
0👍
I tried to send chart as image from Angular 2+ (canvas element) to spring boot for render image to PDF. I encountered blacked background problem. After collecting information about this problem. I decided to unite solution in the one comment to find solution easily at next time.
<canvas #canvas"> </canvas>
@ViewChild('canvas', { static: false }) canvas: ElementRef<HTMLCanvasElement>;
I rendered chart to canvas and get canvas element at .ts file as PNG format and send PNG to backend.
const base64Canvas = this.canvas.nativeElement.toDataURL("image/png").split(';base64,')[1];
Source:stackexchange.com