struts2中 JFreeChart使用

添加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中

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>

写Action

 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 }

就能返回图表

转载于:https://www.cnblogs.com/friends-wf/p/3769574.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值