📄 jfree.jsp
字号:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*,
java.util.*,
org.jfree.chart.ChartRenderingInfo,
org.jfree.chart.JFreeChart,
org.jfree.chart.entity.StandardEntityCollection,
org.jfree.chart.plot.PiePlot,
org.jfree.chart.servlet.ServletUtilities,
java.util.Iterator,
java.util.Hashtable,
org.jfree.chart.ChartFactory,
org.jfree.chart.plot.PlotOrientation,
org.jfree.data.DefaultCategoryDataset,
org.jfree.data.DefaultPieDataset,
imis_hous.com.impl.*,
imis_hous.com.bean.*,
imis_hous.jfree.Hous_tongji" errorPage="" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<jsp:directive.page import="imis_hous.jfree.Hous_tongji"/>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<jsp:useBean id="hous" class="imis_hous.jfree.Hous_tongji"/>
<html>
<head>
<link href="/Imis/imis_hous/css/style.css" rel="stylesheet" type="text/css">
<script language="JavaScript" src="/Imis/imis_hous/jf/checkdata.js">
</script>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>无标题文档</title>
<style type="text/css">
<!--
.style4 {font-size: 14px}
.style5 {font-size: 18px}
-->
</style>
</head>
<body background="/Imis/imis_hous/Add/images/bg_main.png">
<form name="form1" method="post" action="/Imis/servlet/JfreeChar_sl">
<table width="564" border="0" align="center" class="ziti">
<tr>
<td colspan="4"><div align="center"><span class="style5">部门使用房屋统计:</span></div></td>
</tr>
<tr>
<td><span class="style4">建筑物名称:</span></td>
<td>
<select name="BuildingName">
<option selected value=""></option>
<%
HashMap hashDept = new GetBuildName().getDepartment("BuildingNu","BuildingName","Buildings_info");
int length = hashDept.size();
String []deptName = new String[length];//部门数组
String []deptId= new String[length];//部门用房面积数组
Iterator itDeptId = hashDept.keySet().iterator();//键迭代
Iterator itDeptName = hashDept.values().iterator();//值迭代
int i=0;
while(itDeptId.hasNext()){
deptId[i] = itDeptId.next().toString();
i++;
}
i=0;
while(itDeptName.hasNext()){
deptName[i] = itDeptName.next().toString();
i++;
}
for(int j=0;j<length;j++ ){
%>
<option value=<%=deptId[j] %>><%= deptName[j] %></option>
<% }%>
</select>
</td>
<td width="60"><span class="style4">使用部门:</span></td>
<td width="31%">
<select name="UseDept" class="text1">
<option selected value=-1></option>
<%
HashMap hashDept1 = new GetDepartment().getDepartment("OrganId","OrganName","organ");
int length1 = hashDept1.size();
String []deptName1 = new String[length1];//部门数组
int []deptId1= new int[length1];//部门用房面积数组
Iterator itDeptId1 = hashDept1.keySet().iterator();//键迭代
Iterator itDeptName1 = hashDept1.values().iterator();//值迭代
int i1=0;
while(itDeptId1.hasNext()){
deptId1[i1] = Integer.parseInt(itDeptId1.next().toString());
i1++;
}
i1=0;
while(itDeptName1.hasNext()){
deptName1[i1] = itDeptName1.next().toString();
i1++;
}
for(int j=0;j<length1;j++ ){
%>
<option value=<%=deptId1[j] %>><%= deptName1[j] %></option>
<% }%>
</select>
</td>
</tr>
<tr>
<td><span class="style4">分配日期范围</span>从</td>
<td>
<Script class="text1">DateBox("beginTime")</Script>
</td>
<td>到:</td>
<td>
<Script class="text1">DateBox("endTime")</Script></td>
</tr>
<tr>
<td width="73"><span class="style4">分配性质:</span></td>
<td width="168"><select name="J_AssiIs">
<option value="1" selected>私用</option>
<option value="2">公有</option>
<option value="3">其他</option>
</select></td>
<td colspan="2"><input type="submit" name="Submit" value="提交" class="anniu">
<input type="reset" name="Submit2" value="重置" class="anniu"></td>
</tr>
</table>
</form>
<c:if test="${sessionScope.assignTongjiList!=null}">
<%
Hashtable deptRoomArea = (Hashtable)request.getSession().getAttribute("deptRoomArea");
Hashtable deptRoomShu = (Hashtable)request.getSession().getAttribute("deptRoomShu");
ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
//面积比例饼图 //500是图片长度,300是图片高度
String filename1 = ServletUtilities.saveChartAsPNG(getchart(deptRoomArea,1,"部门用房面积比例"), 500, 300, info, session);
String graphURL1 = request.getContextPath() + "/servlet/DisplayChart?filename=" + filename1;
//数量比例饼图
String filename2 = ServletUtilities.saveChartAsPNG(getchart(deptRoomShu,1,"部门用房数量比例"), 500, 300, info, session);
String graphURL2 = request.getContextPath() + "/servlet/DisplayChart?filename=" + filename2;
//面积柱状图
String filename3 = ServletUtilities.saveChartAsPNG(getchart(deptRoomArea,2,"部门用房面积比例"), 500, 300, null, session);
String graphURL3 = request.getContextPath() + "/servlet/DisplayChart?filename=" + filename3;
//数量柱状图
String filename4 = ServletUtilities.saveChartAsPNG(getchart(deptRoomShu,2,"部门用房数量比例"), 500, 300, null, session);
String graphURL4 = request.getContextPath() + "/servlet/DisplayChart?filename=" + filename4;
%>
<%!public static JFreeChart getchart(Hashtable hash,int a,String title){
JFreeChart chart=null;
int length = hash.size();
String []deptname = new String[length];//部门数组
float []deptarea = new float[length];//部门用房面积数组
//
Iterator areaPieKey = hash.keySet().iterator();//键迭代
Iterator areaPieValue = hash.values().iterator();//值迭代
int i=0;
while(areaPieKey.hasNext()){
deptname[i]=(String)areaPieKey.next();
i++;
}
i=0;
while(areaPieValue.hasNext()){
deptarea[i]=Float.parseFloat(areaPieValue.next().toString());
i++;
}
if(a==1){
DefaultPieDataset data = new DefaultPieDataset();
for(int j=0;j<length;j++ )
data.setValue(deptname[j],deptarea[j]);
PiePlot plot = new PiePlot(data);
chart = new JFreeChart("",JFreeChart.DEFAULT_TITLE_FONT, plot, true);
chart.setBackgroundPaint(java.awt.Color.white);//可选,设置图片背景色
chart.setTitle(title);//可选,设置图片标题
}
if(a==2){
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
for(int j=0;j<length;j++ ){
dataset.addValue(deptarea[j],"",deptname[j]);
}
chart = ChartFactory.createBarChart3D(
title, // 图表标题
"部门", // 目录轴的显示标签
"房间数", // 数值轴的显示标签
dataset, // 数据集
PlotOrientation.VERTICAL, // 图表方向:水平、垂直
false, // 是否显示图例(对于简单的柱状图必须是false)
false, // 是否生成工具
false // 是否生成URL链接
);
}
return chart;
}
%>
<table>
<tr><!-- 饼图 -->
<td><img src="<%= graphURL1 %>" width=375 height=225 border=0 ></td>
<td><img src="<%= graphURL2 %>" width=375 height=225 border=0 ></td>
</tr>
<tr><!-- 拄状图 -->
<td><img src="<%= graphURL3 %>" width=375 height=225 border=0 ></td>
<td><img src="<%= graphURL4 %>" width=375 height=225 border=0 ></td>
</tr>
</table>
<table border="0" align="center" class="ziti">
<tr>
<td>建筑物名称</td><td>建筑物面积</td><td>房间号</td><td>房间面积</td><td>朝向</td><td>房间状况</td><td>使用部门</td><td>分配日期</td><td>备注</td>
</tr>
<%
List deptlist = (List)request.getSession().getAttribute("assignTongjiList");
Iterator itDeptArea = deptlist.iterator();
while(itDeptArea.hasNext()){
Tongji_bean tongji = (Tongji_bean)itDeptArea.next();
%>
<tr>
<td align="center"><%= tongji.getBuildingName()%></td>
<td align="center"><%=tongji.getBuildingArea() %></td>
<td align="center"><%=tongji.getRoomNu()%></td>
<td align="center"><%=tongji.getRoomArea() %></td>
<td align="center"><%= tongji.getRoomDirect()%></td>
<td align="center"><%=tongji.getRoomStatus() %></td>
<td align="center"><%=tongji.getUseDept() %></td>
<td align="center"><%=tongji.getRoomAssignDate() %></td>
<td align="center"><%=tongji.getMemo() %></td>
</tr>
<%
}
%>
</table>
</c:if>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -