ServletUtilites.saveChartAsPNG(JFreeChart, int, int, ChartRenderingInfo, HttpSession)
saves the chart in the temporary directory.
But I want the file to be saved in a particular directory(like my home directory)....how would I achieve this.
Regards,
Satish
ServletUtilites.saveChartAsPNG question
Code: Select all
/**
* Save chart to file in PNG format.
*
* @param chart JFreeChart.
* @param fileName Name of PNG file.
* @param width Width of PNG image.
* @param height Height of PNG image.
* @throws IOException
*/
public void saveChartToPNG(JFreeChart chart, String fileName, int width, int height) throws IOException {
if (chart != null) {
if (fileName == null) {
String chartTitle = chart.getTitle().getText();
if (chartTitle != null) {
fileName = chartTitle + ".png";
} else {
fileName = "chart.png";
}
}
ChartUtilities.saveChartAsPNG(new File(fileName), chart, width, height);
}//else: input unavailable
}//saveChartToPNG()
Java 11, JFreeChart 1.0.15, JFreeSVG 4.0
-
- Posts: 115
- Joined: Fri Mar 14, 2003 3:13 pm
- Location: London, England
- Contact:
Changing temp directory location
Alternatively, if you still want to use ServletUtilities, you can change the System property "java.io.tmpdir". The ServletUtilities class and DisplayChart servlet will then use the new directory.
Regards,
Richard...
Regards,
Richard...
can we set other than java.io.tmpdir
Any chance to set other than java.io.tmpdir.
I really want to store chart images in another directory. Can you suggest how to set the same
I really want to store chart images in another directory. Can you suggest how to set the same
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
The options are as given by the other posters:
(1) Use the ChartUtilities class to save the chart in PNG format wherever you want, but the file will never be deleted (unless you take care of that yourself);
(2) Use the ServletUtilities class and save charts in PNG format to the temp directory specified by java.io.tmpdir, with automatic deletion at session expiry.
(1) Use the ChartUtilities class to save the chart in PNG format wherever you want, but the file will never be deleted (unless you take care of that yourself);
(2) Use the ServletUtilities class and save charts in PNG format to the temp directory specified by java.io.tmpdir, with automatic deletion at session expiry.
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


Re: ServletUtilites.saveChartAsPNG question
Hi David
i think that it's better/flexible if we can set the directory stored the chart (actually, it's System.getProperty("java.io.tmpdir") such as a parametre of the servlet
best regards
BO
i think that it's better/flexible if we can set the directory stored the chart (actually, it's System.getProperty("java.io.tmpdir") such as a parametre of the servlet
best regards
BO
Re: ServletUtilites.saveChartAsPNG question
or we can build a method "setStoredDirectory(String dir)" in ServletUtilities