Saving Graphs as Images (Gif)

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

Saving Graphs as Images (Gif)

Post by Jason Clark » Wed Apr 24, 2002 11:33 am

Can anybody post me some example source on how to export/Save a line chart to a gif? (or any other format)

In a nutshell I will be using Tomcat4 (jsp) to create the graphs and display them on a webpage as a image.

Sorry if this has been covered before, but I did a serach and nothing cropped up.

Kind regards,
Jason.

clarkjason@email.com

David Gilbert

Re: Saving Graphs as Images (Gif)

Post by David Gilbert » Wed Apr 24, 2002 11:56 am

The ChartUtilities class has a method writeChartAsPNG(...) that send a PNG format chart image to any OutputStream.

Regards,

DG.

Michael T

Re: Saving Graphs as Images (Gif)

Post by Michael T » Thu Apr 25, 2002 1:19 am

Take a look at the servlet demo.

http://cvs.sourceforge.net/cgi-bin/view ... tDemo.java

In particular, you'll want to write your own servlet that imlements something similar to the doGet() method. In it you can use writeChartAsJPEG() or writeChartAsPNG() (stated by David above).

Then in your JSP you'll want something like

<img src="/servlet/com.foo.MyJFreeChartServlet">

At least that is what I've been testing out for a few days. It will be up to you whether you build the chart in the jsp (nice for quick development) or in the servlet.

Locked