chartjs-node
chartjs-node copied to clipboard
Fix for black background on jpeg output
Hi, I tried to export the image as jpeg but because of the way canvas handles transparency, the background becomes black:
The fix is adding a white rectangle to the background, like this:
plugins: {
beforeDraw: function (chart, easing) {
var ctx = chart.chart.ctx;
ctx.save();
ctx.fillStyle = "#ffffff";
ctx.fillRect(0, 0, chart.width, chart.height);
ctx.restore();
}
}
Maybe this info can be added to wiki or depending on the output, it can be added automatically.
Thanks for this! Saved me some headache.
Thank you @el I can't understand why chartjs doesn't have a native background
property for this purpose.
Thanks! This is very useful!