How to make the chart background transparent when converting to a PNG?

I’m using the Batik conversion code as Vaadin suggests however I need to make the background of the PNG image transparent because it can be displayed in containers of different colors and I don’t want the white border to show. I’ve tried everything I can think of and I can’t seem to find a way to make the background of the PNG transparent. I’ve even tried to force it but it doesn’t work:

chart.getConfiguration().getChart().setBackgroundColor(new SolidColor("#FFFFFF"));

I’ve then tried combinations (either, or both) of:

pngTranscoder.addTranscodingHint(PNGTranscoder.KEY_FORCE_TRANSPARENT_WHITE, Boolean.TRUE);
pngTranscoder.addTranscodingHint(PNGTranscoder.KEY_BACKGROUND_COLOR, java.awt.Color.WHITE);

And nothing seems to work. Any suggestions on how to do this would be greatly appreciated.

Have you tried the R,G,B,Alpha constructor in SolidColor instead? So something like

new SolidColor(255,255,255,0)


If that doesn’t work, one thing to try would be editing the SVG data so that the background element is removed. The background is one big opaque element, after all.


Thank you, that worked perfectly!

Awesome! :slight_smile:

I do seem to remember that I filed a bug saying there should be a constructor override for specifying the alpha channel with the hex string as well, but I can’t find it anymore…