Struts2中使用JfreeChart

阅读更多
1.jar
commons-fileupload-1.2.2.jar
commons-io-2.0.1.jar
commons-lang3-3.1.jar
commons-logging-1.1.1.jar
freemarker-2.3.19.jar
javassist-3.11.0.GA.jar
jcommon-1.0.16.jar
jfreechart-1.0.13.jar
ognl-3.0.5.jar
struts2-core-2.3.4.jar
struts2-jfreechart-plugin-2.3.4.1.jar
xwork-core-2.3.4.jar

2.web.xml


 
	struts2
	org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter


	struts2
	/*

  
  

	DisplayChart
	org.jfree.chart.servlet.DisplayChart


	DisplayChart
	/DisplayChart


  
    index.jsp
  




3.PieAction
package com.sh.action;

import java.awt.Font;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PiePlot;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.general.DefaultPieDataset;

import com.opensymphony.xwork2.ActionSupport;

public class PieAction extends ActionSupport {

	private JFreeChart chart;

	public JFreeChart getChart() {
		//设置 饼图默认的数据集 
		DefaultPieDataset dataset=new DefaultPieDataset();
		dataset.setValue("古典名著", 0.3);
		dataset.setValue("青春校园", 0.1);
		dataset.setValue("儿童读物", 0.3);
		dataset.setValue("异国风情", 0.1);
		dataset.setValue("报刊杂志", 0.2);
		
		chart=ChartFactory.createPieChart3D("图书销量", dataset, true, true, false);
		PiePlot pieplot=(PiePlot) chart.getPlot();
		//定义一个饼图对象
		pieplot.setLabelFont(new Font("宋体",0,12));
		
		TextTitle txtTitle=null;
		txtTitle=chart.getTitle();
		Font font=new Font("宋体",Font.BOLD,16);
		txtTitle.setFont(font);
		chart.getLegend().setItemFont(font);
		
		return chart;
	}

	public void setChart(JFreeChart chart) {
		this.chart = chart;
	}
	
}


4.struts.xml



 
   
   
   		
   			
   				
   				450
   				300
   			
   				
   



5.访问 http://localhost:8083/JfreeChart/pieAction.action
  • JfreeChart.zip (4.9 MB)
  • 下载次数: 27

你可能感兴趣的:(jfreechart,struts)