《Java Web开发技术方案宝典》第5章5.4节统计图决策方案遇到问题
发表在JavaWeb图书答疑
2009-05-25
是否精华
是
否
版块置顶:
是
否
设置时间:
非永久
永久
起始时间:
结束时间:
是否扣分:
是
否
各位明日科技的老师们,您们好,感谢您们百忙之中抽出时间来看我的帖子,希望您们看后能给予我帮助,万分感谢!!!
如何正确运行《Java Web开发技术方案宝典》5.4、5.5和5.6节的绘图程序?
按照说明操作了但是没有出现图?我下载的是《jfreechart-1.0.13》。界面菜单是出来了,但是图出不来?我比较着急。我的问题也许很小儿科,不好意思!敬请回复!谢谢!
如何正确运行《Java Web开发技术方案宝典》5.4、5.5和5.6节的绘图程序?
按照说明操作了但是没有出现图?我下载的是《jfreechart-1.0.13》。界面菜单是出来了,但是图出不来?我比较着急。我的问题也许很小儿科,不好意思!敬请回复!谢谢!
精彩评论 16
2009-06-16
13L
谢谢无语老师的回复,我借用了《jsp数据库系统开发案例精选》企业进销存的年销售额分析的数据及其数据查询方式,datas数组里12个月的数据是有的,每个月也是一一对应的。程序如下。设12个月,在“histogram_Default.setCategory(category);”处出错,设3个月在“histogram_Default.setData(datas);”处出错。我现在搞不清这2个错误的原因及其解决方法,敬请老师指教,谢谢!!!
<%@ page contentType="text/html;charset=gb2312" language="java"%>
<%@ page import="java.io.*,java.sql.*"%>
<%@ page import="java.util.*" pageEncoding="GB2312"%>
<jsp:useBean id="histogram_Default" class="com.mwq.chart.Histogram_Default" scope="session"/>
<jsp:useBean id="rst" scope="page" class="com.mingri.dbconn.DBResult"/>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%
String year=request.getParameter("year");
//获得某年按月份分组的总销售额的SQL语句
String strSql="select sum(je) as sumje,month(xsdate) as xsmonth from tb_sell"+
" where year(xsdate)='"+year+"' group by month(xsdate)";
ResultSet rs=rst.getResult(strSql);
int counts=0;
double max1=0;double min1=0;double mon1=0;
if(!rs.next()){
out.println("<script language='javascript'>alert('"+year+"年没有销售记录');"+
"window.location.href='main.jsp';</script>");
}
else{//获得某年按销售月份分组的总记录数
String strCount="select count(*) as a1,max(sumje) as a2,min(sumje) as a3 from ( "+strSql+" ) as aa";
ResultSet rs1=rst.getResult(strCount);
if(rs1.next())
counts=rs1.getInt(1);
max1=rs1.getInt("a2");
min1=rs1.getInt("a3");
mon1=(max1+min1)/2;
rs1.close();
}
%>
<html>
<title>年销售额分析</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="../CSS/style.css" rel="stylesheet" type="text/css">
<body bgcolor="#F2F2F2">
<table width="77%" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#FFFFFF" bordercolorlight="#9CA6C6" bordercolordark="#CCE3FF">
<tr align="center" bgcolor="#FFFFC1">
<%
if (counts>0){
int chartWidth = 500; //图片宽度
int chartHeight = 300; //图片高度
String chartTitle = "商品销售金额走势分析柱形图"; //图表标题
//String Cutline[] = {"高线", "中线", "低线", "销售金额"}; //图例标题
String Cutline[] = {"销售金额", "低线", "中线", "高线"}; //图例标题
String category[] = {"1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"}; //类别
String xTitle = "统计月份"; //x轴标题
String yTitle = "销售金额(单位:元)"; //y轴标题
double[][] datas = new double[Cutline.length][category.length];
int n=0;int m=n;
try{
for(n=m;n<category.length;n++){
datas[3][n]=max1;
datas[1][n]=min1;
datas[2][n]=mon1;
if(rs.getInt("xsmonth")==n+1){
datas[0][n]=rs.getInt("sumje");
m=n+1;
break;}
}
while(rs.next()){
for(n=m;n<category.length;n++){
datas[3][n]=max1;
datas[1][n]=min1;
datas[2][n]=mon1;
if(rs.getInt("xsmonth")==n+1){
datas[0][n]=rs.getInt("sumje");
m=n+1;
break;}
}
}
}catch(Exception e){
}
histogram_Default.setChartTitle(chartTitle);
histogram_Default.setSubtitle("统计种类:销售金额走势");
histogram_Default.setXTitle(xTitle);
histogram_Default.setYTitle(yTitle);
histogram_Default.setCutline(Cutline);
histogram_Default.setCategory(category);
histogram_Default.setData(datas);
histogram_Default.setContextPath(request.getContextPath());
histogram_Default.setMapName("chartInfo");
histogram_Default.setOut(out);
histogram_Default.setSession(session);
String graphURL=histogram_Default.draw();
%>
<tr align="center">
<td><img src="<%=graphURL %>" usemap="#chartInfo" border="1" alt="" ></td>
</tr>
</table>
<% } %>
<div align="center">
</div>
</body>
</html>
<%@ page contentType="text/html;charset=gb2312" language="java"%>
<%@ page import="java.io.*,java.sql.*"%>
<%@ page import="java.util.*" pageEncoding="GB2312"%>
<jsp:useBean id="histogram_Default" class="com.mwq.chart.Histogram_Default" scope="session"/>
<jsp:useBean id="rst" scope="page" class="com.mingri.dbconn.DBResult"/>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%
String year=request.getParameter("year");
//获得某年按月份分组的总销售额的SQL语句
String strSql="select sum(je) as sumje,month(xsdate) as xsmonth from tb_sell"+
" where year(xsdate)='"+year+"' group by month(xsdate)";
ResultSet rs=rst.getResult(strSql);
int counts=0;
double max1=0;double min1=0;double mon1=0;
if(!rs.next()){
out.println("<script language='javascript'>alert('"+year+"年没有销售记录');"+
"window.location.href='main.jsp';</script>");
}
else{//获得某年按销售月份分组的总记录数
String strCount="select count(*) as a1,max(sumje) as a2,min(sumje) as a3 from ( "+strSql+" ) as aa";
ResultSet rs1=rst.getResult(strCount);
if(rs1.next())
counts=rs1.getInt(1);
max1=rs1.getInt("a2");
min1=rs1.getInt("a3");
mon1=(max1+min1)/2;
rs1.close();
}
%>
<html>
<title>年销售额分析</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="../CSS/style.css" rel="stylesheet" type="text/css">
<body bgcolor="#F2F2F2">
<table width="77%" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#FFFFFF" bordercolorlight="#9CA6C6" bordercolordark="#CCE3FF">
<tr align="center" bgcolor="#FFFFC1">
<%
if (counts>0){
int chartWidth = 500; //图片宽度
int chartHeight = 300; //图片高度
String chartTitle = "商品销售金额走势分析柱形图"; //图表标题
//String Cutline[] = {"高线", "中线", "低线", "销售金额"}; //图例标题
String Cutline[] = {"销售金额", "低线", "中线", "高线"}; //图例标题
String category[] = {"1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"}; //类别
String xTitle = "统计月份"; //x轴标题
String yTitle = "销售金额(单位:元)"; //y轴标题
double[][] datas = new double[Cutline.length][category.length];
int n=0;int m=n;
try{
for(n=m;n<category.length;n++){
datas[3][n]=max1;
datas[1][n]=min1;
datas[2][n]=mon1;
if(rs.getInt("xsmonth")==n+1){
datas[0][n]=rs.getInt("sumje");
m=n+1;
break;}
}
while(rs.next()){
for(n=m;n<category.length;n++){
datas[3][n]=max1;
datas[1][n]=min1;
datas[2][n]=mon1;
if(rs.getInt("xsmonth")==n+1){
datas[0][n]=rs.getInt("sumje");
m=n+1;
break;}
}
}
}catch(Exception e){
}
histogram_Default.setChartTitle(chartTitle);
histogram_Default.setSubtitle("统计种类:销售金额走势");
histogram_Default.setXTitle(xTitle);
histogram_Default.setYTitle(yTitle);
histogram_Default.setCutline(Cutline);
histogram_Default.setCategory(category);
histogram_Default.setData(datas);
histogram_Default.setContextPath(request.getContextPath());
histogram_Default.setMapName("chartInfo");
histogram_Default.setOut(out);
histogram_Default.setSession(session);
String graphURL=histogram_Default.draw();
%>
<tr align="center">
<td><img src="<%=graphURL %>" usemap="#chartInfo" border="1" alt="" ></td>
</tr>
</table>
<% } %>
<div align="center">
</div>
</body>
</html>
2009-06-20
15L
谢谢无语老师的指导,谢谢您百忙之中帮我看程序。这个问题我昨天在偶然试验中用变通的方法解决了。我仔细研究了无语老师的指导和书中的说明,反复做试验,后来我把
String Cutline[] = {"销售金额", "低线", "中线", "高线"}; //图例标题
String category[] = {"1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"}; //类别
的内容做了交换,同时double[][] datas数组的维也做了相应的交换,居然就通过了,图也出来了。谢谢无语老师!!!
无语老师,我现在只能基于书中例子的相关类文件,在jsp文件中进行变通实现自己的作图功能。我希望能够基于书中例子的相关java文件进行修改,用javac编译生成新的class文件,但是无论如何也行不通。即使是把原例的java文件用javac编译生成新的class文件也有好几十个错误。书中例子的相关类文件是如何生成的呢?有什么需要注意的问题?还有对java文件编译生成class文件的其他方法吗?
例如如何对《Java Web开发技术方案宝典》5.6.01图形举一反三呢?几乎所有内容都在java文件编译生成class文件里,如何在jsp文件中进行变通实现自己的功能呢?有没有可以在jsp文件中利用class文件实现动态图的例子?
敬请老师指教,谢谢!!!