我在 jsp 中使用 jfreechart 创建了一个条形图
String path=null;
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.setValue(6, "Profit1", "Jane");
dataset.setValue(3, "Profit2", "Jane");
dataset.setValue(7, "Profit1", "Tom");
dataset.setValue(10, "Profit2", "Tom");
dataset.setValue(8, "Profit1", "Jill");
dataset.setValue(8, "Profit2", "Jill");
dataset.setValue(5, "Profit1", "John");
dataset.setValue(6, "Profit2", "John");
dataset.setValue(12, "Profit1", "Fred");
dataset.setValue(5, "Profit2", "Fred");
// Profit1, Profit2 represent the row keys
// Jane, Tom, Jill, etc. represent the column keys
JFreeChart chart = ChartFactory.createBarChart3D(
"Comparison between Salesman", // Chart name
"Salesman", // X axis label
"Value ($)", // Y axis value
dataset, // data set
PlotOrientation.VERTICAL,
true, true, false);
chart.setBackgroundPaint(Color.white);
// Set the background color of the chart
// Creating a JPEG image
try
{
path= request.getRealPath("images")+"/myChart.jpg";
ChartUtilities.saveChartAsJPEG(new File(path), chart, 500, 300);
System.out.println("image created");
//path=path.replace("\\","/");
}
catch (IOException e)
{
System.err.println("Problem occurred creating chart.");
}
创建的 jpeg 图像
当另存为 png 图像时
path= request.getRealPath("images")+"/myChart.png";
ChartUtilities.saveChartAsPNG(new File(path), chart, 500, 300);
我找不到哪里出错了,我需要 jpeg 图像,就像 png 图像一样。任何想法?