Reputation: 63082
How does one programmatically render image files from JFreeChart . I have code for ChartPanel: is it possible to render directly to an image - without creating AWT/GUI components?
val chart = .. // Imagine code to generate chart data here..
val panel = new ChartPanel(chart)
panel.renderToImage() // replace this with logic to save image file
Upvotes: 3
Views: 896
Reputation: 205795
Use one of the ChartUtilities
methods, such as writeChartAsJPEG()
or writeChartAsPNG()
, that can write to a java.io.OutputStream
; or saveChartAsJPEG()
or saveChartAsPNG()
, that can write to a java.io.File
. Some examples are seen here and here. For example,
ChartUtilities.saveChartAsPNG(new File("chart.png"), chart, width, height);
You'll also want to look into headless mode, mentioned here.
Upvotes: 3