首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

Struts2调整Jfreechart

2012-11-15 
Struts2整合Jfreechart准备:需要的jarjfreechar的jarStruts的jarStruts整合jfreechar的插件包 struts2-jfr

Struts2整合Jfreechart
准备:需要的jar

jfreechar的jar
Struts的jar
Struts整合jfreechar的插件包 struts2-jfreechart-plugin-2.1.8.1.jar

1.struts.xml配置
<package name="char" namespace="/char" extends="jfreechart-default">     <action name="*-*" method="{2}">           <result name = "success" type = "chart" >                    <param name = "width" > 600 </param >                    <param name = "height" > 400 </param >                </result >        </action></package>

?

2. action配置
package com.wepull.jfreeChart.action;import org.jfree.chart.JFreeChart;import com.opensymphony.xwork2.ActionSupport;import com.wepull.jfreeChart.chart.CreateChart;public class ChartAction extends ActionSupport {private JFreeChart chart;  //属性名必须为chartpublic String showChart(){chart = CreateChart.exportPiechart();return SUCCESS;}public JFreeChart getChart() {  //必须通过get方法return chart;}}

?

3. CreateChart 类
public class CreateChart {public static JFreeChart exportPiechart() {DefaultPieDataset dataset = new DefaultPieDataset();dataset.setValue("经济舱总售票" + 105, 105);dataset.setValue("商务舱总售票" + 30, 30);dataset.setValue("头等舱总售票" + 50, 50);JFreeChart chart = ChartFactory.createPieChart3D("客户统计图", dataset,true, true, true);chart.setTitle(new TextTitle("售票统计图", new Font("黑体", Font.ITALIC, 14)));// 标题字体// 设置图例部分LegendTitle legend = chart.getLegend(0);// 设置图的部分PiePlot plot = (PiePlot) chart.getPlot();plot.setLabelFont(new Font("宋体", Font.BOLD, 12));// 设置实际统计图的字体plot.setBackgroundAlpha(0.9f);plot.setForegroundAlpha(0.50f);return chart;}}
?4. 前台页面
<html>  <head>     <title>My JSP 'index.jsp' starting page</title>  </head>    <body>    <a href="chart/Chart-showChart">查看统计图</a>  </body></html>

?

热点排行