JFreeChart改变图片的保存路径

继承ServletUtilities,若生成的图片格式为jpg,则重写saveChartAsJPEG方法

public static String saveChartAsJPEG(JFreeChart chart, int width,
int height, HttpSession session) throws IOException {
if (chart == null) {
throw new IllegalArgumentException("Null 'chart' argument.");
}
ServletUtilities.createTempDir();
String prefix = ServletUtilities.getTempFilePrefix();
if (session == null) {
prefix = ServletUtilities.getTempOneTimeFilePrefix();
}
File dir = new File("图片要保存的路径");
if (!dir.exists()) {
dir.mkdirs();
}
File tempFile = File.createTempFile(prefix, ".jpg", dir);
ChartUtilities.saveChartAsPNG(tempFile, chart, width, height);
if (session != null) {
ServletUtilities.registerChartForDeletion(tempFile, session);
}
return tempFile.getName();
}

你可能感兴趣的:(jfreechart)