ServletUtilites.saveChartAsPNG question

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Guest

ServletUtilites.saveChartAsPNG question

Post by Guest » Mon Jun 21, 2004 7:40 pm

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

mhilpert
Posts: 497
Joined: Wed Apr 02, 2003 1:57 pm
Location: Germany

Post by mhilpert » Tue Jun 22, 2004 10:00 am

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

richard_atkinson
Posts: 115
Joined: Fri Mar 14, 2003 3:13 pm
Location: London, England
Contact:

Changing temp directory location

Post by richard_atkinson » Tue Jun 22, 2004 9:11 pm

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...

Tirupathi

can we set other than java.io.tmpdir

Post by Tirupathi » Tue Jan 10, 2006 9:44 am

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

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Tue Jan 10, 2006 3:56 pm

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.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

BO
Posts: 61
Joined: Wed Mar 01, 2006 2:17 pm

Re: ServletUtilites.saveChartAsPNG question

Post by BO » Mon May 17, 2010 8:29 am

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

BO
Posts: 61
Joined: Wed Mar 01, 2006 2:17 pm

Re: ServletUtilites.saveChartAsPNG question

Post by BO » Mon May 17, 2010 12:42 pm

or we can build a method "setStoredDirectory(String dir)" in ServletUtilities

Locked