我在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);
我无法找到我出错的地方,我需要像png图像一样的jpeg图像。 有什么想法吗?