Transparent Background

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
gopinath
Posts: 12
Joined: Wed Feb 17, 2010 1:21 pm
antibot: No, of course not.

Transparent Background

Post by gopinath » Wed Feb 17, 2010 1:27 pm

Help me to set a transparent background for PieChart

Thanks,
Gopi

jleech
Posts: 62
Joined: Fri Oct 26, 2007 9:18 pm

Re: Transparent Background

Post by jleech » Fri Feb 19, 2010 5:06 pm

Call setBackgroundPaint(null) on the chart and on its plot, the legend, etc. If you want a partially transparent color instead of full transparency, use the appropriate constructor for java.awt.Color and pass that object to the same setBackgroundPaint() methods. Output to an image format that supports transparency. If this is going on the web, be aware of the limitations of the Internet Explorer browser and transparency in png.

gopinath
Posts: 12
Joined: Wed Feb 17, 2010 1:21 pm
antibot: No, of course not.

Re: Transparent Background

Post by gopinath » Mon Apr 26, 2010 1:13 pm

Dear jleech,
Thanks for your reply.
plot.setBackgroundPaint(null) with backgroundAlpha(0.0f) gives plot with transparent background and it reflects the color of the chart.
but
chart.setBackgroundPaint(null) gives black background and hence the whole background appears black.

Is there any possibility to generate transparent background image such that the background color of the html container(in browser) is appears to be the image background.

Thanks,
Gopi.

jleech
Posts: 62
Joined: Fri Oct 26, 2007 9:18 pm

Re: Transparent Background

Post by jleech » Mon Apr 26, 2010 7:31 pm

What kind of image are you creating? I had a similar issue with PNG images, though I was doing some non-standard JFreeChart stuff though. I am not sure which of the following was necessary with standard JFreechart output to an image, and which was self-imposed... I ended up making a 256 color indexed BufferedImage, setting every pixel to white before calling chart.draw() on it, then using JAI to modify the palette transparency to fully opaque for all colors but white, and fully transparent for white, and encode to png. (So that anti-aliased text would look good in all browsers, otherwise text was unreadable in IE with its half-assed PNG support). There is likely an easier way, but the above worked for me. Creating a transparent GIF, or a non-indexed PNG, and/or not using anti-aliasing probably works fine.

Locked