The tutorials using images AND jfreechart are lacking
because they assume you can place the image on the page at a given X,Y
coordinate. Most real world layouts will not allow for this, and the graphs
should be done “within” the document flow.
This is achievable by the following:
/* inject code as you will */
ByteArrayOutputStream bos = new
ByteArrayOutputStream();
ChartUtilities.writeChartAsJPEG(
bos, chart, 400, 300 );
Toolkit tk =
Toolkit.getDefaultToolkit();
java.awt.Image img = tk.createImage(
bos.toByteArray() );
/* we now have a valid image object */
/* later on in your code */
Paragraph p = new Paragraph();
com.lowagie.text.Image itextImg =
com.lowagie.text.Image.getInstance( img, offsetX, offsetY );
p.add( itextImg );
document.add( p );
/* the image should now appear amid the document flow
properly without having to resort to X,Y hardcoding */
== Stanton