Hi!
I have a program that generate a couple of charts dinamically. After some periodic calculations, the charts are updated with a new bar during a period user-defined.
I know that with the right-click button we can save the chart as an image. But can I access the method to save the chart as an image programatically?
I mean, an image of the final chart must be saved and I don't want ask the user to do it. I wanna do it programatically...
Is it possible?
Thanks in advance!
Programatically save a chart as an image
Re: Programatically save a chart as an image
Look at org.jfree.chart.ChartUtilities
Re: Programatically save a chart as an image
That stuff is a piece of sh**. It generates a low quality image (even if the image quality float is maximized), with lower (yes, it can be lower) quality text on it. Sadly there's no other method for saving a chart to file...skunk wrote:Look at org.jfree.chart.ChartUtilities
Re: Programatically save a chart as an image
If you don't want to deal with ChartUtilities, I suggest you have a look at the ScreenImage class. I never used it myself, but it looks rather simple.
http://tips4java.wordpress.com/2008/10/13/screen-image/
Basically, all you have to do is create a chart, add this chart to a ChartPanel, call the method ScreenImage.createImage(...), and eventually call the method ScreenImage.writeImage(...) to store the image to a file.
http://tips4java.wordpress.com/2008/10/13/screen-image/
Basically, all you have to do is create a chart, add this chart to a ChartPanel, call the method ScreenImage.createImage(...), and eventually call the method ScreenImage.writeImage(...) to store the image to a file.
Code: Select all
JFreeChart chart = ChartFactory.createLineChart(...);
ChartPanel panel = new ChartPanel(chart);
ScreenImage.writeImage(ScreenImage.createImage(panel), "myImageFile.jpg");
Re: Programatically save a chart as an image
Thank you for the replies!
No problem in using the org.jfree.chart.ChartUtilities...
I'll try using this class.
No problem in using the org.jfree.chart.ChartUtilities...
I'll try using this class.
Re: Programatically save a chart as an image
By clicking in "Save Image" in context menu (clicking directly on generated map) who method is called? org.jfree.chart.ChartUtilities.saveChartAsPNG ?skunk wrote:Look at org.jfree.chart.ChartUtilities
Thanks in advance!
Re: Programatically save a chart as an image
Read the source for org.jfree.chart.ChartPanel
Code: Select all
public void doSaveAs() throws IOException {