6

In JFreeChart is there a notion of a composite Chart.

I need to layout several charts in a grid like arrangement.

Each chart in the grid needs to have its own separate title.

I would like to be able to save this composite chart into a png file

I would get a code snippet that explains how to do this.

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
user1172468
  • 5,306
  • 6
  • 35
  • 62

1 Answers1

7

As shown here, ChartPanel can be placed in any desired Swing layout. The example cited uses GridLayout. ChartUtilities has methods for rendering a chart as a .png. I see several approaches to getting a composite image:

  • Use Robot#createScreenCapture() to image the layout, as shown here and here; the resulting BufferedImage can be saved using ImageIO.write().

  • Use JFreeChart#createBufferedImage() to render each chart and impose the individual images into a BufferedImage to create a single image, as suggested here.

  • Implement the Printable interface to render the image in a graphics context, as shown here.

image

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • many thanks for the answer ... it worked for me ... related question: I'd like to save the resulting composite chat into an png ... any suggestions ? – user1172468 Apr 05 '13 at 01:35
  • so what do I pass to the JFrame to the ImageIO? Thanks. – user1172468 Apr 05 '13 at 01:55
  • you might want to look at my question: http://stackoverflow.com/questions/15856325/plotting-a-locus-in-xy-space-using-jfreechart Thanks – user1172468 Apr 06 '13 at 21:43
  • Maybe it's too late to talk but, i want to ask something. Can you update these thermometers with timer? How? – AloneInTheDark Feb 25 '14 at 09:22
  • @AloneInTheDark: Yes; use `javax.swing.Timer`, for [example](http://stackoverflow.com/a/19833774/230513), or `javax.swing.SwingWorker`, for [example](http://stackoverflow.com/a/13205322/230513). – trashgod Feb 25 '14 at 17:31