Printing with ChartPanel
Printing with ChartPanel
I need to print extra text information while printing chart panel with right button click. Does anybody has a clue how to do it? I'd assume I need to override print method in ChartPanel, but how?
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
Re: Printing with ChartPanel
All the printing happens within this method in the ChartPanel class:
You can override this method and draw anything you want using the Graphics2D instance (that is provided by the printing API).
Code: Select all
@Override
public int print(Graphics g, PageFormat pf, int pageIndex) {
if (pageIndex != 0) {
return NO_SUCH_PAGE;
}
Graphics2D g2 = (Graphics2D) g;
double x = pf.getImageableX();
double y = pf.getImageableY();
double w = pf.getImageableWidth();
double h = pf.getImageableHeight();
this.chart.draw(g2, new Rectangle2D.Double(x, y, w, h), this.anchor,
null);
return PAGE_EXISTS;
}
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
Re: Printing with ChartPanel
Thank you, works and very helpful.