how do I create a transparent PNG chart?

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Paul Sijpkes

how do I create a transparent PNG chart?

Post by Paul Sijpkes » Wed Jul 24, 2002 6:06 am

Hi all,

I'm trying to set the background for my simple bar chart PNG to a
transparency.

I've tried setting the background colour with a 0 alpha value

// start code **

chart.setBackgroundPaint(new GradientPaint(0, 0, new Color(255,255,255,0), 1000, 0, new Color(255,255,255,0)));

// end code **

and creating my own slightly modified PNG creation method:

// start code **

BufferedImage chartImage = chart.createBufferedImage(width, height, info);
PngEncoder encoder = new PngEncoder(chartImage, true, 0, 9);
byte[] pngData = encoder.pngEncode();
out.write(pngData);

// end code **

but I still get a bar chart with a solid black background.

Does anyone have any ideas?

regards,
Paul.

mark shvets

Re: how do I create a transparent PNG chart?

Post by mark shvets » Tue Aug 20, 2002 1:23 am

I habve exactly the same problem. Any solution would be greatly appreciated.

JD Degenaar

Re: how do I create a transparent PNG chart?

Post by JD Degenaar » Thu Dec 05, 2002 3:17 pm

There seems to be a three-month-old feature request for this. Nobody has attempted at even looking at it though.

#577279 Transparent background for chart images

Would be nice to have this though as using JFreeChart is pointless unless you are going to use web backgrounds that are white.

David Gilbert

Re: how do I create a transparent PNG chart?

Post by David Gilbert » Mon Dec 09, 2002 11:37 pm

JD Degenaar wrote:
> There seems to be a three-month-old feature request for this.
> Nobody has attempted at even looking at it though.

Not quite true. I've looked at that feature request (and all of the others) but it has not yet risen high enough on *my* priority list to get implemented by *me*. But one of the key features of free (in the GNU sense) software is that you are not forced to depend on me to get new features implemented...you have other options.

> #577279 Transparent background for chart images
>
> Would be nice to have this though as using JFreeChart is
> pointless unless you are going to use web backgrounds that
> are white.

I think generating images with transparency would be a great feature, and I'm confident that it will be added to a future version (perhaps even by me). But I don't agree that JFreeChart is "pointless" without that feature though.

Regards,

DG

JD Degenaar

Re: how do I create a transparent PNG chart?

Post by JD Degenaar » Tue Dec 10, 2002 9:12 am

My apologies for coming on too strongly about the issue. JFreeChart according to me is still the best utility out on the net.


My reason for saying what I said though simply played a role in the fact that I implemented various charts into some of my pages and found that the chart background breaks the CSS color scheme horribly on any I try to use.

I have ( during my spare time ) started doing some investigation into my issues with the application. Will contact you with a solution as soon as I find a way to improve the creation of the chart image. Hopefully in the next month or so as time permits.

Locked