- 浏览: 140345 次
- 性别:
- 来自: 厦门
最新评论
-
占星:
[b][flash=200,200][url][img][li ...
hibernate结合spring怎么处理对象的延迟加载? -
accphc:
...
处理properties文件中key包含空格和等号的情况 -
赵武艺:
有没有办法不让jfreechart热点刷新页面?
有热点的JfreeChart柱型图(原创)[转] -
yuchensuifeng:
谢谢分享!刚学这个,现在去试试!
在struts2中使用JFreeChart -
wrrwhn:
Caused by: There is no result t ...
在struts2中使用JFreeChart
继续上一篇的 在struts2中使用JasperReports,这篇是如何在web页面上输出chart(图表)。
1、在struts2中,默认的struts-default.xml中,并没有包含chart的result-type,它是插件的形式使用的。把 struts2的解压包的lib里找到struts2-jfreechart-plugin-2.0.11.jar,拷贝到你的项目的 classpath里,同时在struts.xml里面增加一个chart的result-type。
2、需要再添加jfreechart-1.0.9.jar和jcommon-1.0.12.jar(JasperReports和JFreeChart都需要的)到你的classpath里面。
3、在你的action代码里,返回一个JFreeChart对象即可。
ListAllFruit4Bar2Action代码:
ListAllFruit4Pie2Action代码:
FruitService代码:
4、同时在jsp页面里显示--柱图和饼图。
增加一个ListAllFruit4BarAndPie的action:
ListAllFruit4BarAndPie.jsp代码:
生成的HTML的效果图如下:
下面是除了依赖的jar以外的所有源代码,share出来,欢迎下载。
这里是错的哈, <param name="chart">chart</param>
应该为 <param name="value">chart</param>
后面的chart为你action中定义的域变量,比如piechart或什么什么的
为什么最后的Java代码 <action name="ListAllFruit4BarAndPie" class=""> <result name="success" type="dispatcher">/WEB-INF/chart/ListAllFruit4BarAndPie.jsp</result> </action> <action name="ListAllFruit4BarAndPie" class="">
<result name="success" type="dispatcher">/WEB-INF/chart/ListAllFruit4BarAndPie.jsp</result>
</action>中的class的值为空呢?
最后一个是List Action,默认是直接返回SUCCESS,使用空的Action,其实是默认使用了ActionSupport
1、在struts2中,默认的struts-default.xml中,并没有包含chart的result-type,它是插件的形式使用的。把 struts2的解压包的lib里找到struts2-jfreechart-plugin-2.0.11.jar,拷贝到你的项目的 classpath里,同时在struts.xml里面增加一个chart的result-type。
<result-types> <result-type name="chart" class="org.apache.struts2.dispatcher.ChartResult"/> </result-types> <action name="ListAllFruit4Bar2" class="chart.ListAllFruit4Bar2Action"> <result name="success" type="chart"> <param name="chart">chart</param> <param name="height">400</param> <param name="width">700</param> </result> </action> <action name="ListAllFruit4Pie2" class="chart.ListAllFruit4Pie2Action"> <result name="success" type="chart"> <param name="chart">chart</param> <param name="height">400</param> <param name="width">700</param> </result> </action>
2、需要再添加jfreechart-1.0.9.jar和jcommon-1.0.12.jar(JasperReports和JFreeChart都需要的)到你的classpath里面。
3、在你的action代码里,返回一个JFreeChart对象即可。
ListAllFruit4Bar2Action代码:
package chart; import org.jfree.chart.JFreeChart; import com.opensymphony.xwork2.ActionSupport; public class ListAllFruit4Bar2Action extends ActionSupport { private static final long serialVersionUID = 1L; private JFreeChart chart; @Override public String execute() throws Exception { chart = FruitService.createBarChart(); return SUCCESS; } public JFreeChart getChart() { return chart; } }
ListAllFruit4Pie2Action代码:
package chart; import org.jfree.chart.JFreeChart; import com.opensymphony.xwork2.ActionSupport; public class ListAllFruit4Pie2Action extends ActionSupport { private static final long serialVersionUID = 1L; private JFreeChart chart; @Override public String execute() throws Exception { chart = FruitService.createPaiChart(); return SUCCESS; } public JFreeChart getChart() { return chart; } }
FruitService代码:
package chart; import org.jfree.chart.ChartFactory; import org.jfree.chart.JFreeChart; import org.jfree.chart.plot.PlotOrientation; import org.jfree.data.category.CategoryDataset; import org.jfree.data.category.DefaultCategoryDataset; public class FruitService { public static JFreeChart createBarChart() { CategoryDataset dataset = getDataSet2(); JFreeChart chart = ChartFactory.createBarChart3D( "水果产量图", // 图表标题 "水果", // 目录轴的显示标签 "产量", // 数值轴的显示标签 dataset, // 数据集 PlotOrientation.VERTICAL, // 图表方向:水平、垂直 true, // 是否显示图例(对于简单的柱状图必须是false) true, // 是否生成工具 true // 是否生成URL链接 ); return chart; } private static CategoryDataset getDataSet2() { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.addValue(100, "北京", "苹果"); dataset.addValue(100, "上海", "苹果"); dataset.addValue(100, "广州", "苹果"); dataset.addValue(200, "北京", "梨子"); dataset.addValue(200, "上海", "梨子"); dataset.addValue(200, "广州", "梨子"); dataset.addValue(300, "北京", "葡萄"); dataset.addValue(300, "上海", "葡萄"); dataset.addValue(300, "广州", "葡萄"); dataset.addValue(400, "北京", "香蕉"); dataset.addValue(400, "上海", "香蕉"); dataset.addValue(400, "广州", "香蕉"); dataset.addValue(500, "北京", "荔枝"); dataset.addValue(500, "上海", "荔枝"); dataset.addValue(500, "广州", "荔枝"); return dataset; } public static JFreeChart createPaiChart() { DefaultPieDataset data = getDataSet(); JFreeChart chart = ChartFactory.createPieChart3D("水果产量图", // 图表标题 data, true, // 是否显示图例 false, false ); PiePlot plot = (PiePlot) chart.getPlot(); resetPiePlot(plot); return chart; } private static void resetPiePlot(PiePlot plot) { String unitSytle = "{0}={1}({2})"; plot.setNoDataMessage("无对应的数据,请重新查询。"); plot.setNoDataMessagePaint(Color.red); //指定 section 轮廓线的厚度(OutlinePaint不能为null) plot.setOutlineStroke(new BasicStroke(0)); //设置第一个 section 的开始位置,默认是12点钟方向 plot.setStartAngle(90); plot.setToolTipGenerator(new StandardPieToolTipGenerator(unitSytle, NumberFormat.getNumberInstance(), new DecimalFormat("0.00%"))); //指定图片的透明度 plot.setForegroundAlpha(0.65f); //引出标签显示样式 plot.setLabelGenerator(new StandardPieSectionLabelGenerator(unitSytle, NumberFormat.getNumberInstance(), new DecimalFormat("0.00%"))); //图例显示样式 plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator(unitSytle, NumberFormat.getNumberInstance(), new DecimalFormat("0.00%"))); } private static DefaultPieDataset getDataSet() { DefaultPieDataset dataset = new DefaultPieDataset(); dataset.setValue("苹果",100); dataset.setValue("梨子",200); dataset.setValue("葡萄",300); dataset.setValue("香蕉",400); dataset.setValue("荔枝",500); return dataset; } }
4、同时在jsp页面里显示--柱图和饼图。
增加一个ListAllFruit4BarAndPie的action:
<action name="ListAllFruit4BarAndPie" class=""> <result name="success" type="dispatcher">/WEB-INF/chart/ListAllFruit4BarAndPie.jsp</result> </action>
ListAllFruit4BarAndPie.jsp代码:
<%@ page contentType="text/html; charset=UTF-8" %> <html> <head> <title>ListAllFruit4BarAndPie</title> </head> <body> <center><h2>使用柱图和饼图列取所有水果产量</h2></center> 柱图:<img src="chart/ListAllFruit4Bar2.action"><br/> 饼图:<img src="chart/ListAllFruit4Pie2.action"> </body> </html>
生成的HTML的效果图如下:
下面是除了依赖的jar以外的所有源代码,share出来,欢迎下载。
- JasperReportsDemo-chart.rar (44.1 KB)
- 描述: 包含chart的JasperReportsDemo
- 下载次数: 1152
评论
9 楼
yuchensuifeng
2012-05-02
谢谢分享!刚学这个,现在去试试!
8 楼
wrrwhn
2011-08-23
Caused by: There is no result type defined for type 'chart' mapped with name 'success'. Did you mean 'chart'? - result - file:/D:/Program%20Files/Apache%20Software%20Foundation/Tomcat%206.0/webapps/WareStore/WEB-INF/classes/struts.xml:59:40
你好,在使用你的方法中,出现了此种情况,请问你是否还有印象,此种情况是哪里出错吗?
你好,在使用你的方法中,出现了此种情况,请问你是否还有印象,此种情况是哪里出错吗?
7 楼
wu_yaowen
2010-01-13
<action name="ListAllFruit4Bar2" class="chart.ListAllFruit4Bar2Action"> <result name="success" type="chart"> <param name="chart">chart</param> <param name="height">400</param> <param name="width">700</param> </result> </action> <action name="ListAllFruit4Pie2" class="chart.ListAllFruit4Pie2Action"> <result name="success" type="chart"> <param name="chart">chart</param> <param name="height">400</param> <param name="width">700</param> </result> </action>
这里是错的哈, <param name="chart">chart</param>
应该为 <param name="value">chart</param>
后面的chart为你action中定义的域变量,比如piechart或什么什么的
6 楼
liyanboss
2009-05-27
zhouwendong006 写道
为什么最后的Java代码 <action name="ListAllFruit4BarAndPie" class=""> <result name="success" type="dispatcher">/WEB-INF/chart/ListAllFruit4BarAndPie.jsp</result> </action> <action name="ListAllFruit4BarAndPie" class="">
<result name="success" type="dispatcher">/WEB-INF/chart/ListAllFruit4BarAndPie.jsp</result>
</action>中的class的值为空呢?
最后一个是List Action,默认是直接返回SUCCESS,使用空的Action,其实是默认使用了ActionSupport
5 楼
zhouwendong006
2009-05-20
为什么最后的
中的class的值为空呢?
<action name="ListAllFruit4BarAndPie" class=""> <result name="success" type="dispatcher">/WEB-INF/chart/ListAllFruit4BarAndPie.jsp</result> </action>
中的class的值为空呢?
4 楼
yehaoren
2009-03-13
你好,我想问下,# plot.setToolTipGenerator(new StandardPieToolTipGenerator(unitSytle,
# NumberFormat.getNumberInstance(),
# new DecimalFormat("0.00%")));
这段代码是不是生成鼠标提示的,你的例子里,提示好像显示不出来啊
# NumberFormat.getNumberInstance(),
# new DecimalFormat("0.00%")));
这段代码是不是生成鼠标提示的,你的例子里,提示好像显示不出来啊
3 楼
w469
2009-03-02
谢谢!!!!!
对我帮助很大!
对我帮助很大!
2 楼
shaqiang32
2008-09-28
李大哥,我是小刘啊,居然在javaeye都能碰到,,,这个好像是你上次教我的那个报表程序?
1 楼
liukidd
2008-05-04
如果数据量大,这种方法可行吗?
发表评论
-
Subversion的安装配置
2008-08-06 10:15 2480Subversion是很好用的版本控制工具,以前自己也动手安装 ... -
处理properties文件中key包含空格和等号的情况
2008-06-12 16:11 14183在properties文件中都是以key=value的方式存储 ... -
mysql修改root密码
2008-05-07 10:20 2845mysql 更改密码如下(本人刚刚测试过的RH9.0): 在 ... -
tomcat的OutOfMemoryError解决方法
2008-05-04 14:54 5993最近在熟悉一个开发了有几年的项目,需要把数据库从mysql移植 ... -
使用ant执行sql脚本重建oracle数据库
2008-04-21 17:26 5885最近工作中,需要把之前的产品(基于mysql数据库的)转换到o ... -
struts2+spring2+hibernate3 Annotation的整合
2008-04-16 15:22 6759继续前两篇文章[在struts2中使用JFreeChart ] ... -
在struts2中使用JasperReports
2008-04-09 10:49 5928最近工作中要求可以把网页信息以报表的形式输出,虽然以前有接触过 ... -
有热点的JfreeChart柱型图(原创)[转]
2008-04-07 11:04 3523实现方式:jsp+javabean 版本 :jfreecha ... -
hibernate结合spring怎么处理对象的延迟加载?
2008-01-23 13:01 2281在hibernate3中所有从数据库查询出来的数据,都是默认l ... -
自定义类型安全的枚举
2008-01-18 13:09 1435package com.goodhope.tradingapp ... -
基于spring,acegi,jcaptcha的验证码
2008-01-17 10:37 1937首先,在你的web.xml里加入过滤器"Acegi ... -
已有字数:4,剩余字数:196
2008-01-15 19:57 1456function CountNodeNum(Obj) { ... -
spring mail sender
2008-01-13 18:23 1261import java.util.Properties; i ... -
eclipse反编译插件Jadclipse的使用
2007-06-13 17:56 3977jadclips插件网站: http://jadcli ... -
如何使用ant的bulid.xml
2007-04-25 08:55 4187最近电脑系统有些问题,硬盘全部被格式化,原来的所有文件都没有了 ... -
使用keytool生成SSL双向认证
2007-01-25 08:32 4200Microsoft Windows XP [版本 5.1.26 ...
相关推荐
struts2整合jfreechart简单实用实例,包含饼状图、柱状图、折线图.
struts2整合 jfreechart 实现报表组件
这是一个获取用户信息的投票系统,包含需求及代码,可以了解投票系统的基本需求,如何分析和设计数据库、使用JSP +JavaBean+Struts2+JDBC+JFreeChart进行开发、学会MySQL数据库的基本使用、使用JFreeChart画柱状图、...
struts2-jfreechart-plugin-2.1.8.1.jar
NULL 博文链接:https://takeme.iteye.com/blog/1717062
struts2-jfreechart-plugin-2.0.11.jarstruts2-jfreechart-plugin-2.0.11.jarstruts2-jfreechart-plugin-2.0.11.jar
继上次发的普通web下的jfreechart应用demo,struts2下jfreechart的应用,源码
最新官方struts2-plugin jfreechart,分享于有需要的朋友
struts2整合JFreechart: jcommon-1.0.16.jar jfreechart-1.0.13.jar struts2-jfreechart-plugin-2.0.11.jar 导成图片操作说明
struts2 jfreechart使用的jar包 struts2 jfreechart使用的jar包 struts2 jfreechart使用的jar包
Struts2 和 JFreeChart结合使用的实例,可直接运行!
有些struts2中的包结合jfreechart,图形不能显示出来。。。这个是自己测试过,一个个包试过的。。
知识点:struts2,struts2模型驱动,Java反射,struts2插件使用,struts2与JFreeChart的集成开发,JFreeChart图表 1、开发环境:MyEclipse6.0, Struts 2.0.11, JFreeChart 1.0.9, JCommon 1.0.12,struts2-jfreechart...
struts2-jfreechart-plugin-2.0.8.jar
JFreeChart 是一个非常流行的一个免费开源的图表软件,已经有8年以上的历史。本文档将详解struts2如何整合Jfreechart完成报表功能。同时通过此文档,我们还会学到struts2与第三方插件整合的方法原理。
对于struts1和JFreeChart开发,灵活从jsp页面转向Action到页面
struts2-jfreechart-plugin-2.1.6.jar