JFreeChart : how do you put multiple charts into a composite chart
Asked Answered
I

1

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.

Inoculation answered 4/4, 2013 at 7:56 Comment(0)
M
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

Mantic answered 4/4, 2013 at 9:54 Comment(5)
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 ?Inoculation
so what do I pass to the JFrame to the ImageIO? Thanks.Inoculation
you might want to look at my question: #15856825 ThanksInoculation
Maybe it's too late to talk but, i want to ask something. Can you update these thermometers with timer? How?Scribner
@AloneInTheDark: Yes; use javax.swing.Timer, for example, or javax.swing.SwingWorker, for example.Mantic

© 2022 - 2024 — McMap. All rights reserved.