Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why is the background black when with Chartjs export to a image

I have a problem when i try to export the chart to an image. The backgound is black and this is the code:

var canvas=ctx;
var canvasImg = canvas.toDataURL("image/png", 1.0);

//creates PDF from img
var doc = new jsPDF('landscape');
doc.setFontSize(20);
doc.text(15, 15, "Cool Chart");
doc.addImage(canvasImg, 'JPEG', 10, 10, 280, 150 );
doc.save('canvas.pdf');
like image 224
WILSON CHACÓN Avatar asked Sep 19 '25 11:09

WILSON CHACÓN


1 Answers

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.

like image 50
Anne Gunn Avatar answered Sep 22 '25 01:09

Anne Gunn