I created a bar chart using jfreechart in a jsp
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.");
}
the jpeg image created
when saved as png image
path= request.getRealPath("images")+"/myChart.png";
ChartUtilities.saveChartAsPNG(new File(path), chart, 500, 300);
I could not find where i go wrong, i need jpeg image as like png image. Any idea?