码迷,mamicode.com
首页 > 其他好文 > 详细

struts2中 JFreeChart使用

时间:2014-06-05 13:27:15      阅读:295      评论:0      收藏:0      [点我收藏+]

标签:c   style   class   blog   code   java   

添加3个包

struts2-jfreechart-plugin-2.3.16.3.jar

jcommon-1.0.16.jar

jfreechart-1.0.13.jar

 

struts.xml中配置

查看struts2-jfreechart-plugin-2.3.16.3.jar中的struts-plugin.xml文件

查看其中的定义的东西 然后写着struts.xml中

bubuko.com,布布扣
1     <package name="freechart" extends="jfreechart-default">
2         <action name="freechart" class="cn.itcast.chart.MyFreeChart">
3 
4                 <result type="chart" name="success" >
5                     <param name="height">800</param>
6                     <param name="width">600</param>
7                 </result>
8         </action>
9     </package>
bubuko.com,布布扣

写Action

bubuko.com,布布扣
 1 package cn.itcast.chart;
 2 
 3 import java.io.Serializable;
 4 
 5 import org.jfree.chart.JFreeChart;
 6 import org.jfree.chart.axis.NumberAxis;
 7 import org.jfree.chart.axis.ValueAxis;
 8 import org.jfree.chart.plot.XYPlot;
 9 import org.jfree.chart.renderer.xy.StandardXYItemRenderer;
10 import org.jfree.data.xy.XYSeries;
11 import org.jfree.data.xy.XYSeriesCollection;
12 
13 import com.opensymphony.xwork2.ActionSupport;
14 
15 public class MyFreeChart extends ActionSupport implements Serializable {
16     private JFreeChart chart;
17 
18     public JFreeChart getChart() {
19         return chart;
20     }
21     public String execute(){
22         ValueAxis xAxis = new NumberAxis("年度");
23         ValueAxis yAxis = new NumberAxis("产值");
24         XYSeries xySeries = new XYSeries("绿豆");
25         xySeries.add(0,300);
26         xySeries.add(1,200);
27         xySeries.add(2,400);
28         xySeries.add(3,500);
29         xySeries.add(4,600);
30         xySeries.add(5,500);
31         xySeries.add(6,800);
32         xySeries.add(7,1000);
33         xySeries.add(8,1100);
34         XYSeriesCollection xyDataset = new XYSeriesCollection(xySeries);
35         XYPlot xyPlot = new XYPlot(xyDataset,xAxis,yAxis,new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES_AND_LINES));
36         chart = new JFreeChart(xyPlot);
37         return SUCCESS;
38     }
39 }

就能返回图表
bubuko.com,布布扣

struts2中 JFreeChart使用,布布扣,bubuko.com

struts2中 JFreeChart使用

标签:c   style   class   blog   code   java   

原文地址:http://www.cnblogs.com/friends-wf/p/3769574.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!