chart and pie
来源:互联网 发布:图章制作软件 编辑:程序博客网 时间:2024/09/21 08:54
under stuts1.1 JSP
Display.jsp================================
<body>
This is my JSP page. <br>
<P ALIGN="CENTER">
<%String url=(String)session.getAttribute("url"); %><!--EL works too-->
<img src="<%=url %>" width=500 height=300 border=0 usemap="#map0">
</P>
</body>
Login.jsp================================
<body>
This a struts page. <br>
<html:form action="/chart.do">
<html:submit/>
</html:form>
</body>
struts-config.xml Configuration===================
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<struts-config>
<data-sources >
<data-source key="mssql2000">
<set-property property="password" value="" />
<set-property property="minCount" value="1" />
<set-property property="maxCount" value="4" />
<set-property property="user" value="sa" />
<set-property property="driverClass" value="com.microsoft.jdbc.sqlserver.SQLServerDriver" />
<set-property property="description" value="" />
<set-property property="url" value="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs" />
<set-property property="readOnly" value="false" />
<set-property property="autoCommit" value="true" />
<set-property property="loginTimeout" value="" />
</data-source>
</data-sources>
<form-beans >
<form-bean name="pieForm" type="com.struts.form.PieForm" />
</form-beans>
<global-exceptions />
<global-forwards />
<action-mappings >
<action
attribute="pieForm"
input="/login.jsp"
name="pieForm"
path="/chart"
scope="request"
type="com.struts.action.ChartAction"
validate="false">
<forward
name="ok"
path="/Display.jsp"
contextRelative="true" />
</action>
</action-mappings>
<message-resources parameter="com.struts.ApplicationResources" />
</struts-config>
Web.xml Configuration========================
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>3</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>3</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
</servlet>
<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>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
</web-app>
Src----------------------------------
formbean=======================
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.struts.form;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
/**
* MyEclipse Struts
* Creation date: 02-19-2004
*
* XDoclet definition:
* @struts.form name="pieForm"
*/
public class PieForm extends ActionForm {
/*
* Generated fields
*/
/** pienum property */
private String pienum;
/** piename property */
private String piename;
/** pieid property */
private String pieid;
/*
* Generated Methods
*/
/**
* Method validate
* @param mapping
* @param request
* @return ActionErrors
*/
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
// TODO Auto-generated method stub
return null;
}
/**
* Method reset
* @param mapping
* @param request
*/
public void reset(ActionMapping mapping, HttpServletRequest request) {
// TODO Auto-generated method stub
}
/**
* Returns the pienum.
* @return String
*/
public String getPienum() {
return pienum;
}
/**
* Set the pienum.
* @param pienum The pienum to set
*/
public void setPienum(String pienum) {
this.pienum = pienum;
}
/**
* Returns the piename.
* @return String
*/
public String getPiename() {
return piename;
}
/**
* Set the piename.
* @param piename The piename to set
*/
public void setPiename(String piename) {
this.piename = piename;
}
/**
* Returns the pieid.
* @return String
*/
public String getPieid() {
return pieid;
}
/**
* Set the pieid.
* @param pieid The pieid to set
*/
public void setPieid(String pieid) {
this.pieid = pieid;
}
}
action-----------------------------
ChartAction====================
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.struts.action;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Vector;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
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.labels.StandardPieToolTipGenerator;
import org.jfree.chart.plot.PiePlot3D;
import org.jfree.chart.servlet.ServletUtilities;
import org.jfree.data.general.DefaultPieDataset;
import com.business.ChartBusiness;
import com.struts.form.PieForm;
/**
* MyEclipse Struts
* Creation date: 02-19-2004
*
* XDoclet definition:
* @struts.action validate="true"
*/
public class ChartAction extends Action {
/*
* Generated Methods
*/
/**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
// TODO Auto-generated method stub
ChartBusiness cb=new ChartBusiness();
Vector vc=cb.findAll();
DefaultPieDataset data = new DefaultPieDataset();
//数据初始化
// data.setValue("高中以下",380);
// data.setValue("高中",1620);
// data.setValue("大专",6100);
// data.setValue("本科",8310);
// data.setValue("硕士",3520);
// data.setValue("博士",180);
for(int i=0;i<vc.size();i++)
{
PieForm p=new PieForm();
p=(PieForm) vc.get(i);
data.setValue(p.getPiename(),Integer.parseInt(p.getPienum()));
}
//HttpSession session = request.getSession();
PiePlot3D plot = new PiePlot3D(data);//生成一个3D饼图
//plot.setURLGenerator(new StandardPieURLGenerator("DegreedView.jsp"));//设定图片链接
JFreeChart chart = new JFreeChart("",JFreeChart.DEFAULT_TITLE_FONT, plot, true);
chart.setBackgroundPaint(java.awt.Color.white);//可选,设置图片背景色
chart.setTitle("程序员学历情况调查表-By Alpha");//可选,设置图片标题
plot.setToolTipGenerator(new StandardPieToolTipGenerator());
StandardEntityCollection sec = new StandardEntityCollection();
ChartRenderingInfo info = new ChartRenderingInfo(sec);
PrintWriter w=null;
try {
PrintWriter out=response.getWriter();
w = new PrintWriter(out);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//500是图片长度,300是图片高度
//String filename = ServletUtilities.saveChartAsPNG(chart,500,300,info,session);
HttpSession session=request.getSession(true);
String filename="";
try {
filename = ServletUtilities.saveChartAsJPEG(chart,500,300,info,session);
ChartUtilities.writeImageMap(w,"map0",info,false);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String graphURL = request.getContextPath() + "/servlet/DisplayChart?filename=" + filename;
session.setAttribute("url", graphURL);
return mapping.findForward("ok");
}
}
DBConnection=============================
package com.db;
import java.sql.*;
import java.util.*;
import javax.sql.*;
import org.apache.struts.action.ActionServlet;
public class DBConnection {
private static Connection con;
private static DBConnection dbcon = new DBConnection();
private DBConnection() {
}
public static DBConnection getDBConnection() {
return dbcon;
}
public static Connection geConnection() {
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
} catch (ClassNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
con = DriverManager
.getConnection(
"jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs",
"sa", "");
return con;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return con;
}
}
Dao================================
package com.dao;
import java.sql.*;
import java.util.Vector;
import com.db.*;
import com.struts.form.*;
public class ChartDao {
public Vector findAll()
{
Vector chartvc=new Vector();
String sql="select * from pie";
DBConnection dbcon=DBConnection.getDBConnection();
Connection con=dbcon.geConnection();
Statement st=null;
ResultSet rs=null;
try {
st=con.createStatement();
rs=st.executeQuery(sql);
if(rs!=null)
{
while(rs.next())
{
PieForm p=new PieForm();
p.setPieid(rs.getString(1));
p.setPiename(rs.getString(2));
p.setPienum(rs.getString(3));
chartvc.add(p);
}
}
return chartvc;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally
{
try {
rs.close();
st.close();
con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return chartvc;
}
}
Business==============================
package com.business;
import java.util.Vector;
import com.dao.ChartDao;
public class ChartBusiness {
public Vector findAll()
{
ChartDao cd=new ChartDao();
return cd.findAll();
}
}
sql =====================
create table pie
(
pieid int identity primary key,
piename varchar(20) not null,
pienum varchar(20)not null
)
OVER pie JPEG show up
- chart and pie
- Set Height and Width Pie Chart
- Dynamically creating a pie chart with ASP.NET and GDI+
- flex3.0 chart pie
- dojo.Chart2D----Pie chart
- Pie Chart "Key"
- Silverlight Pie Chart
- ExtJS - Pie Chart
- Pie Chart 学习例子
- easy-pie-chart
- jfreechart生成Multiple Pie Chart
- CodeProject: 3D Pie Chart.
- open flash chart with struts2 pie
- Android报表库aChartEngine-pie chart
- JQuery flot pie chart plugin简单例子
- Android报表库aChartEngine系列(pie chart)
- Pie Chart——饼状图控件
- Kibana displays customized percentage in pie chart
- 撰写日志类
- PowerDesigner 12.5 导致的 Office Word 2007 鼠标在文档中无效的问题
- 中国干部行政级别
- 从CodeProject那里找到并且剥离出来的一个Trace Log类
- 《算法导论》数论知识总结(二)
- chart and pie
- asp.net优化完全技巧
- jsp的路径汇总
- My OA T_SQL
- 学习网2
- 我希望我的员工能做到的事
- 移动上网青睐社交网站 校内网位列中文第一
- SSH
- prototype中文文档