The current print method createChartPrintJob() prints one chart.
I have a case where the screen has 4 charts and I need to print all those charts on a single page. It is an 800by600 size screen with 4 charts.
Looked at the print method in the source code and saw...
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();
chart.draw(g2, new Rectangle2D.Double(x, y, w, h), null);
return PAGE_EXISTS;
}
Is there anyway I can combine the four different charts into a single unique chart and pass it to the createChartPrintJob() method?
Thanks in advance.
Printing more than one chart
Re: Printing more than one chart
The ChartPanel class implements the Printable interface to make it simple to print a single chart (there is only one chart in a ChartPanel). But there is nothing to stop you writing your own class that:
(a) contains four charts (or any number you want);
(b) implements the Printable interface;
(c) uses code similar to the above, except draws each chart in one quadrant on the page, something like this:
chart1.draw(g2, quadrant1, null);
chart2.draw(g2, quadrant2, null);
chart3.draw(g2, quadrant3, null);
chart4.draw(g2, quadrant4, null);
Regards,
DG.
(a) contains four charts (or any number you want);
(b) implements the Printable interface;
(c) uses code similar to the above, except draws each chart in one quadrant on the page, something like this:
chart1.draw(g2, quadrant1, null);
chart2.draw(g2, quadrant2, null);
chart3.draw(g2, quadrant3, null);
chart4.draw(g2, quadrant4, null);
Regards,
DG.