How to save chart as image file?

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

How to save chart as image file?

Post by Joe Chen » Thu Aug 08, 2002 3:40 pm

Hi,

Can anybody give me an example to save a created chart as an image file so that I can have it embedded into a pdf file through xslt parsing using FOP?
Would very much appreciate.

Joe Chen

Frank

Re: How to save chart as image file?

Post by Frank » Thu Aug 08, 2002 4:10 pm

If you want to save it as an jpg file. Use the chartutilities class.Here is some sample code:
// create a chart...
JFreeChart chart = ChartFactory.createPieChart("Chart Name" , data, true);

// create and display a frame...
ChartUtilities util = new ChartUtilities();

String fileName = new String ("c://projects//TomcatJBoss//charts//" +"FileName" +".jpg");

try
{
util.saveChartAsJPEG(new File(fileName), chart, 685, 445);
}
catch(IOException e)
{
}

Joe Chen

Re: How to save chart as image file?

Post by Joe Chen » Thu Aug 08, 2002 6:06 pm

Frank,
Thank you so much! It works just fine for me.
Joe

Locked