Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for black background on jpeg output #64

Open
el opened this issue Oct 16, 2018 · 3 comments
Open

Fix for black background on jpeg output #64

el opened this issue Oct 16, 2018 · 3 comments

Comments

@el
Copy link
Contributor

el commented Oct 16, 2018

Hi, I tried to export the image as jpeg but because of the way canvas handles transparency, the background becomes black:

testimage

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();
      }
    }

testimage-w

Maybe this info can be added to wiki or depending on the output, it can be added automatically.

@solomania9
Copy link

Thanks for this! Saved me some headache.

@doleron
Copy link

doleron commented Jun 19, 2020

Thank you @el I can't understand why chartjs doesn't have a native background property for this purpose.

@uzkha
Copy link

uzkha commented Jan 19, 2021

Thanks! This is very useful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants