您的位置:程序门 -> java -> web 开发



struts2+jfreechart生成热点图片的问题


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


struts2+jfreechart生成热点图片的问题
发表于:2008-01-23 12:12:55 楼主
目标:用struts2+jfreechart+struts2-jfreechart-plugin-2.0.9插件做有链接的饼状图
我的代码:
1.web.xml文件添加struts2的过滤器
2.struts.xml文件中加
xml code
<include file="struts-jfreechart.xml" />

3.这是struts-jfreechart.xml文件内容
xml code
<!doctype struts public "-//apache software foundation//dtd struts configuration 2.0//en" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <package name="jfreechartdemonstration" extends="struts-default"> <result-types> <result-type name="chart" class="org.apache.struts2.dispatcher.chartresult"></result-type> </result-types> <action name="jfreechartaction" class="com.coraise.action.jfreechartaction"> <result type="chart"> <param name="width">400</param> <param name="height">300</param> </result> </action> </package> </struts>

4.这是struts2-jfreechart-plugin-2.0.9插件中chartresult.java源代码
java code
import com.opensymphony.xwork2.actioncontext; import com.opensymphony.xwork2.actioninvocation; import com.opensymphony.xwork2.result; import com.opensymphony.xwork2.util.valuestack; import java.io.outputstream; import java.io.printwriter; import javax.servlet.http.httpservletresponse; import org.apache.struts2.servletactioncontext; import org.jfree.chart.chartrenderinginfo; import org.jfree.chart.chartutilities; import org.jfree.chart.jfreechart; import org.jfree.chart.entity.standardentitycollection; import org.jfree.chart.servlet.servletutilities; public class chartresult implements result { public chartresult() { chartset = false; } public chartresult(jfreechart chart, int height, int width) { chartset = false; setchart(chart); this.height = height; this.width = width; } public chartresult setchart(jfreechart chart) { this.chart = chart; chartset = true; return this; } public chartresult setheight(int height) { this.height = height; return this; } public chartresult setwidth(int width) { this.width = width; return this; } public void EXECute(actioninvocation invocation) throws exception { jfreechart chart = null; if(chartset) chart = this.chart; else chart = (jfreechart)invocation.getstack().findvalue("chart"); if(chart == null) { throw new nullpointerexception("no chart found"); } else { httpservletresponse response = servletactioncontext.getresponse(); outputstream os = response.getoutputstream(); chartutilities.writechartaspng(os, chart, width, height); //以下为个人加的代码 standardentitycollection entitycollection = new standardentitycollection(); chartrenderinginfo info = new chartrenderinginfo(entitycollection); printwriter pw = new printwriter(os); chartutilities.writeimagemap(pw,"map0", info,false); //以上为个人加的代码 os.flush(); return; } } private static final long serialversionuid = 0xa6017f6fda50aa4cl; jfreechart chart; boolean chartset; private int height; private int width; }

5.这是我的jfreechartaction的代码
java code
import java.awt.*; import org.jfree.chart.chartfactory; import org.jfree.chart.chartrenderinginfo; import org.jfree.chart.jfreechart; import org.jfree.chart.entity.standardentitycollection; import org.jfree.chart.labels.standardpietooltipgenerator; import org.jfree.chart.plot.pieplot; import org.jfree.chart.title.legendtitle; import org.jfree.chart.urls.standardpieurlgenerator; import org.jfree.data.general.defaultpiedataset; import com.opensymphony.xwork2.actionsupport; public class jfreechartaction extends actionsupport{ private static final long serialversionuid = 5752180822913527064l; private jfreechart chart; private defaultpiedataset getdata() { defaultpiedataset data = new defaultpiedataset(); data.setvalue("java", new double(43.2)); data.setvalue("visual basic", new double(1.0)); data.setvalue("c/c++", new double(17.5)); data.setvalue("tangjun", new double(60.0)); return data; } @override public string EXECute() throws exception { return success; } public jfreechart getchart() { chart = chartfactory.createpiechart("",getdata(),true,true,true); legendtitle legend = chart.getlegend(0); legend.setitemfont(new font("宋体", font.bold, 13)); pieplot plot = (pieplot) chart.getplot(); plot.setlabelfont(new font("隶书", font.bold, 26)); plot.seturlgenerator(new standardpieurlgenerator("index.jsp")); plot.settooltipgenerator(new standardpietooltipgenerator()); return chart; } }

6.myjsp.jsp页面嵌入的代码 <img   src="jfreechartaction.action">
结果:myjsp.jsp页面出统计图,但这个统计图不是动态的,既没提示,也无链接.
请问怎么该才能成为有提示和链接的效果啊
发表于:2008-01-23 13:20:491楼 得分:0
帮顶!
发表于:2008-01-23 13:36:442楼 得分:0
图书出售,
java2核心技术卷i:基础知识(原书第7版)
详细说明:http://product.dangdang.com/product.aspx?product_id=9167161   原价:88

java2核心技术,卷ii:高级特性(原书第7版)
详细说明:http://product.dangdang.com/product.aspx?product_id=9155128   原价:108

java   web开发详解:xml+xslt+servlet+jsp深入剖析与实例应用(附光盘)  
详细说明:http://product.dangdang.com/product.aspx?product_id=9167911   原价:99

effective   java中文版
详细说明:http://product.dangdang.com/product.aspx?product_id=707050   原价:39

java与xslt  
详细说明:http://product.dangdang.com/product.aspx?product_id=725436   原价:55

java网络编程(第3版)——o'reilly   java系列  
详细说明:http://product.dangdang.com/product.aspx?product_id=9062293   原价:85

junit   in   action   中文版——java人的工具箱系列  
详细说明:http://product.dangdang.com/product.aspx?product_id=8935882   原价:39

spring专业开发指南  
详细说明:http://product.dangdang.com/product.aspx?product_id=9202403   原价:80

spring   2.0技术手册(附光盘)
详细说明:http://product.dangdang.com/product.aspx?product_id=9303590   原价:49.8

深入浅出hibernate  
详细说明:http://product.dangdang.com/product.aspx?product_id=8991354   原价:59

struts   2   权威指南:基于webwork核心的mvc开发(附光盘)  
详细说明:http://product.dangdang.com/product.aspx?product_id=20029121&mode=new   原价:79

oracle高级编程  
详细说明:http://product.dangdang.com/product.aspx?product_id=9296670   原价:69

sql   server   2005宝典(附盘)  
详细说明:http://product.dangdang.com/product.aspx?product_id=9247242   原价:79

以上书籍完好无损,均以4.5折出售,如需邮寄,邮费自付。qq:492717188   tel:13450830512   谢谢!
发表于:2008-01-23 14:38:383楼 得分:0
我的帖子沉的真快.我想这个问题都3天了,还是出不来.希望知道的帮下


快速检索

最新资讯
热门点击