jfreechart问题?
jfreechart问题?在jsp上做jfreechart图形,想通过html连接下载该图形,怎么做?...
jfreechart问题?
在jsp上做 jfreechart图形,想通过html连接下载该图形,怎么做? 展开
在jsp上做 jfreechart图形,想通过html连接下载该图形,怎么做? 展开
2个回答
2013-09-13
展开全部
我以前做的
Code如下:
<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<%@ page import="org.jfree.data.general.DefaultPieDataset"%>
<%@ page import="org.jfree.chart.*"%>
<%@ page import="org.jfree.chart.plot.*"%>
<%@ page import="org.jfree.chart.servlet.ServletUtilities"%>
<%@ page import="org.jfree.chart.labels.StandardPieToolTipGenerator"%>
<%@ page import="org.jfree.chart.urls.StandardPieURLGenerator"%>
<%@ page import="org.jfree.chart.entity.StandardEntityCollection"%>
<%@ page import="java.io.*"%>
<%@ page import="com.csthit.store.dao.*" %>
<%@ page import="com.csthit.store.vo.*" %>
<html>
<head>
<%
TypeDAO typedao=new TypeDAO();
SalesDAO sales=null;
FatherType father=null;
List list=null;
list=typedao.getFatherType();
%>
<title>销售图</title>
<%
DefaultPieDataset data = new DefaultPieDataset();
//数据动态初始化
for(int i=0;i<list.size();i++) {
sales=new SalesDAO();
father=(FatherType)list.get(i);
data.setValue(father.getType(),sales.queryQuantityByType(father.getType())); //设值
}
PiePlot3D plot = new PiePlot3D(data);//生成一个3D饼图
JFreeChart chart = new JFreeChart("",JFreeChart.DEFAULT_TITLE_FONT, plot, true);
chart.setBackgroundPaint(java.awt.Color.lightGray);//可选,设置图片背景色
chart.setTitle("图书销量统计图");//可选,设置图片标题
plot.setToolTipGenerator(new StandardPieToolTipGenerator());
StandardEntityCollection sec = new StandardEntityCollection();
ChartRenderingInfo info = new ChartRenderingInfo(sec);
PrintWriter w = new PrintWriter(out);//输出MAP信息
//500是图片长度,300是图片高度
String filename = ServletUtilities.saveChartAsJPEG(chart,500,300,info,session);
ChartUtilities.writeImageMap(w,"map0",info,false);
String graphURL = request.getContextPath() + "/servlet/DisplayChart?filename=" + filename;
%>
</head>
<body>
<center>
<img src="<%= graphURL %>" width=500 height=300 border=0 usemap="#map0">
</center>
</body>
</html>
XML配置如下:
<servlet>
<servlet-name> DisplayChart </servlet-name>
<servlet-class> org.jfree.chart.servlet.DisplayChart </servlet-class>
</servlet>
<servlet-mapping>
<servlet-name> DisplayChart </servlet-name>
<url-pattern> /servlet/DisplayChart </url-pattern>
</servlet-mapping>
Code如下:
<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<%@ page import="org.jfree.data.general.DefaultPieDataset"%>
<%@ page import="org.jfree.chart.*"%>
<%@ page import="org.jfree.chart.plot.*"%>
<%@ page import="org.jfree.chart.servlet.ServletUtilities"%>
<%@ page import="org.jfree.chart.labels.StandardPieToolTipGenerator"%>
<%@ page import="org.jfree.chart.urls.StandardPieURLGenerator"%>
<%@ page import="org.jfree.chart.entity.StandardEntityCollection"%>
<%@ page import="java.io.*"%>
<%@ page import="com.csthit.store.dao.*" %>
<%@ page import="com.csthit.store.vo.*" %>
<html>
<head>
<%
TypeDAO typedao=new TypeDAO();
SalesDAO sales=null;
FatherType father=null;
List list=null;
list=typedao.getFatherType();
%>
<title>销售图</title>
<%
DefaultPieDataset data = new DefaultPieDataset();
//数据动态初始化
for(int i=0;i<list.size();i++) {
sales=new SalesDAO();
father=(FatherType)list.get(i);
data.setValue(father.getType(),sales.queryQuantityByType(father.getType())); //设值
}
PiePlot3D plot = new PiePlot3D(data);//生成一个3D饼图
JFreeChart chart = new JFreeChart("",JFreeChart.DEFAULT_TITLE_FONT, plot, true);
chart.setBackgroundPaint(java.awt.Color.lightGray);//可选,设置图片背景色
chart.setTitle("图书销量统计图");//可选,设置图片标题
plot.setToolTipGenerator(new StandardPieToolTipGenerator());
StandardEntityCollection sec = new StandardEntityCollection();
ChartRenderingInfo info = new ChartRenderingInfo(sec);
PrintWriter w = new PrintWriter(out);//输出MAP信息
//500是图片长度,300是图片高度
String filename = ServletUtilities.saveChartAsJPEG(chart,500,300,info,session);
ChartUtilities.writeImageMap(w,"map0",info,false);
String graphURL = request.getContextPath() + "/servlet/DisplayChart?filename=" + filename;
%>
</head>
<body>
<center>
<img src="<%= graphURL %>" width=500 height=300 border=0 usemap="#map0">
</center>
</body>
</html>
XML配置如下:
<servlet>
<servlet-name> DisplayChart </servlet-name>
<servlet-class> org.jfree.chart.servlet.DisplayChart </servlet-class>
</servlet>
<servlet-mapping>
<servlet-name> DisplayChart </servlet-name>
<url-pattern> /servlet/DisplayChart </url-pattern>
</servlet-mapping>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-09-13
展开全部
写饼图之前要先引入二个Jar文件:jfreechart-1.0.10.jar和jcommon-1.0.13.jar
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询