//水晶报表生成柱状图的前提是要在webroot下的WEB-INF添加jfreechart-1.0.2.jar和jcommon-1.0.5.jar(这是我自己的版本)
import java.io.FileOutputStream;
import java.io.IOException;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
public class TestjFreeChart {
public static void main(String[] args) throwsIOException{
CategoryDataset dataset =getDataSet();
JFreeChart chart =ChartFactory.createBarChart3D(
"水果产量图",// 图表标题
"水果",// 目录轴的显示标签
"产量",// 数值轴的显示标签
dataset,// 数据集
PlotOrientation.VERTICAL,// 图表方向:水平、垂直
true, // 是否显示图例(对于简单的柱状图必须是false)
false, // 是否生成工具
false // 是否生成URL链接
);
FileOutputStream fos_jpg =null;
try {
fos_jpg = newFileOutputStream("I:\\fruit.jpg");
ChartUtilities.writeChartAsJPEG(fos_jpg,1,chart,400,300,null);
} finally {
try {
fos_jpg.close();
} catch(Exception e) {}
}
}
private static CategoryDataset getDataSet(){
DefaultCategoryDataset dataset= new DefaultCategoryDataset();
dataset.addValue(100, "aaa","苹果");
dataset.addValue(200, "aaa","梨子");
dataset.addValue(300, "aaa","葡萄");
dataset.addValue(400, "aaa","香蕉");
dataset.addValue(500, "aaa","荔枝");
return dataset;
}