struts JFreeChart

一、需要包和插件:struts2-jfreechart-plugin-2.0.11.jar,jfreechart-1.0.9.jar,jcommon-1.0.12.jar 

二、从配置文件开始:在struts.xml文件增加一个对生成图表包,如下:
 
<package name="chartaction" extends="jfreechart-default">
  <action name="zhuzhuang" class="com.action.chart.testChartAction"  method="load">
   <result name="success" type="chart">
          <param name="height">400</param>   
           <param name="width">700</param>   
   </result>
  </action>
 
  <action name="bingzhuang" class="com.action.chart.testChartAction" method="load2">
   <result name="success" type="chart">  
          <param name="height">400</param>   
           <param name="width">700</param>   
   </result>
  </action>
 
 </package>
 
三、创建Action类,代码:
 
package com.action.chart;
/**
 * 测试JFreeChart
 */
import org.jfree.chart.JFreeChart;
 
import com.opensymphony.xwork2.ActionSupport;
import com.service.FruitService;
 
public class testChartAction extends ActionSupport {
 private JFreeChart chart;   
    
    public String load() throws Exception {
       chart = FruitService.createBarChart(); 
       return SUCCESS;   
    } 

    public String load2() throws Exception {   
        chart = FruitService.createPaiChart();   
         return SUCCESS;   
     }
 
    public JFreeChart getChart() {   
        return chart;   
    }   

}
 
(FruitService类是用来整合专门生成JFreeChart图表的类,详细如何生成chart图,这里不再赘述)
 
四、jsp页面表现输出图片
 
<body>
<img src="zhuzhuang.action"/>
<img src="bingzhuang.action"/>
</body>

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