Printing a chart

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

Printing a chart

Post by Anup Kurian » Tue Oct 08, 2002 10:52 pm

I looked through the JFreeChart Documentation about Printing a currently displayed chart. It only says printing can be easily accomplished, but now how.

Can anyone suggest some pointers on printing the currently displayed chart...I have a set of toolbars and other buttons I dont want to print, but only the chart.

Dave Gilbert

Re: Printing a chart

Post by Dave Gilbert » Wed Oct 09, 2002 9:04 am

Hi Anup,

The ChartPanel class has a simple print facility built in.

The createChartPrintJob() method sets up and starts a print job that makes use of the fact that the ChartPanel class implements the Printable interface.

The print(...) method (which gets called by the print job) draws the chart onto the Graphics2D instance provided by the print job. By default, the chart uses the entire page, but you could write similar code that places a chart at any size/location.

You don't have to use the code in ChartPanel, you could write something similar anywhere in your code where you have access to the JFreeChart object.

Regards,

DG.

Anup K

Re: Printing a chart

Post by Anup K » Wed Oct 09, 2002 2:51 pm

Thanks for the reply.

Just one doubt...when I call the ChartPanel print function, it is redrawing on the screen, not the printer.

Do I have to make a PrinterJob and call the print function associated with that?

Or is there anyway I can make it print on a printer rather than redrawing on the screen?

Anup K

Re: Printing a chart

Post by Anup K » Wed Oct 09, 2002 3:01 pm

Sorry, everything works fine, please disregard my earlier post.

Locked