Print ChartPanel with modifications

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Ted Hill
Posts: 54
Joined: Mon Jun 12, 2006 7:39 pm

Print ChartPanel with modifications

Post by Ted Hill » Tue Sep 29, 2009 3:50 pm

Hello,

In my application, I display a ChartPanel without a Title or a Legend. (The application displays this information elsewhere outside of the ChartPanel.)

However, when I print the ChartPanel, I'd like to be able to print it with ChartPanel's Title and Legend.

Is there someway to override the ChartPanel.createChartPrintJob() in order to add a title and legend?

Or simply create another instance of the Chart with a title and legend that is not displayed on screen and send that to the printer?

Other suggestions?

Thanks.
Ted Hill

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: Print ChartPanel with modifications

Post by david.gilbert » Tue Sep 29, 2009 8:36 pm

You should be able to clone the chart that is being managed by the ChartPanel, then add a legend and a title to the clone, then print that. Cloning the chart will not clone the underlying dataset, although you can do that manually if it is something you need.

There are lots of JUnit tests that check the cloning, but I think most people don't ever use the cloning feature, so be sure to test your code thoroughly and report any bugs you encounter.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

Ted Hill
Posts: 54
Joined: Mon Jun 12, 2006 7:39 pm

Re: Print ChartPanel with modifications

Post by Ted Hill » Tue Sep 29, 2009 9:50 pm

Thank you very much -- works perfectly!
Ted Hill

Locked