Struts2整合图表工具 JFreeChart

1首先下载和安装最新的jcommon

http://sourceforge.net/projects/jfreechart/files/3.%20JCommon/1.0.18/jcommon-1.0.18.zip/download

2下载最新的jfreeChart

http://sourceforge.net/projects/jfreechart/files/latest/download?source=directory

3导入俩个包

jcommon-1.0.17.jar

jfreechart-1.0.14.jar

3解决java web中,中文乱码。在apache servlet中,替换

 

<Connector 
port="8080"  maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
               enableLookups="false" redirectPort="8443" acceptCount="100"
               debug="0" connectionTimeout="20000" 
               disableUploadTimeout="true" URIEncoding="UTF-8"/>

4我的一个示例

	public void search() throws IOException{
		JFreeChart chart = ChartFactory.createPieChart("图书销量统计图", this.getDataSet(), true, false, false);
		chart.setTitle(new TextTitle("图书销量统计图",new Font("黑体",Font.BOLD,22)));
		LegendTitle legend = chart.getLegend(0);
		legend.setItemFont(new Font("宋体",Font.BOLD,14));
		PiePlot plot = (PiePlot)chart.getPlot();
		plot.setLabelFont(new Font("隶书",Font.BOLD,18));
		plot.setBackgroundAlpha(0.9f);
		FileOutputStream fos = new FileOutputStream("d:/book.jpg");
		ChartUtilities.writeChartAsJPEG(fos,1,chart,800,600,null);
		fos.close();
}
	private static DefaultPieDataset getDataSet(){
		DefaultPieDataset dataset = new DefaultPieDataset();
		dataset.setValue("信息开发1", 47);
		dataset.setValue("造船信息122", 38);
		dataset.setValue("疯狂ajax讲义", 31);
		dataset.setValue("疯狂xml讲义", 12);
		return dataset;
		
	}

  

5一个非常好的jfreeChart博客

雷霆山崖

http://www.cnblogs.com/xingyun/archive/2012/02/05/2339237.html 

你可能感兴趣的:(jfreechart)