my eclipse 中使用chart
<%@pagecontentType="text/html;charset=gb2312"language="java"%><%@pageimport="java.io....
<%@ page contentType="text/html;charset=gb2312" language="java"%>
<%@ page import="java.io.*,java.sql.*"%>
<jsp:useBean id="rst" scope="page" class="com.mlh.dao.sqldao"/>
<%
String year=request.getParameter("year");
//获得某年按月份分组的总销售额的SQL语句
String strSql="select sum(je) as sumje,month(date) as xsmonth from tb_sell"+
" where year(date)='"+year+"' group by month(date)";
ResultSet rs=rst.getResult(strSql);
int counts=0;
if(!rs.next()){
out.println("<script language='javascript'>alert('"+year+"年没有销售记录');"+
"window.location.href='main.jsp';</script>");
}
else{//获得某年按销售月份分组的总记录数
String strCount="select count(*) from ( "+strSql+" ) as aa";
ResultSet rs1=rst.getResult(strCount);
if(rs1.next())
counts=rs1.getInt(1);
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="820" border="1" align="center" cellpadding="0"cellspacing="0" bordercolor="#FFFFFF" bordercolorlight="#9CA6C6" bordercolordark="#CCE3FF" height="63">
<tr align="center" bgcolor="#FFFFC1">
<td height="50" bgcolor="#FFFFC1">
<%
if (counts>0){
%>
<!--定义一个对象该对象名为chart-->
<object classid="clsid:3A2B370C-BA0A-11D1-B137-0000F8753F5D" name="chart" width="100%" height="255">
</object>
<%
for(int j=1;j<=counts;j++){ //循环从1循环到counts
%>
<script language="javascript">
charts("pillar"); //调用charts()函数
function charts(type){
if (type=="line"){
chart.chartType=3;
//chartType是对象chart的属性:表示图形类型
}
if (type=="pillar" ){
chart.chartType=1;
}
chart.ColumnCount=1; //ColumnCount是对象chart的属性:表示设置与图表关联的当前数据网格中的列数。
chart.Title="<%=year%>年销售额分析表"; //图表标题
chart.rowcount=<%=counts%>; //rowcount属性:数据行个数。
chart.row=<%=j%>; //row属性:当前数据行
chart.rowlabel="<%=rs.getString("xsmonth")%>月"; //rowlabel属性:返回/设置一个数据标签,该标签用来标识图表中当前数据点。横坐标值
chart.Data=<%=rs.getString("sumje")%>; //Data属性:当前数据点的值。纵坐标值
chart.Footnote="注:纵坐标为销售额,单位为(元) ;空缺的月份没有销售额"
}
</script>
<%
rs.next();
}
%>
</td>
</tr>
</table>
<table width="97%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="26" align="center">
<form name="form1" method="post" action="">
<input type="button" class="btn_grey" onClick="charts('pillar')" value="柱状图分析">
<input type="button" class="btn_grey" onClick="charts('line')" value="线性图分析">
</form> </td>
</tr>
</table>
<% } %>
<div align="center">
</div>
</body>
</html> 展开
<%@ page import="java.io.*,java.sql.*"%>
<jsp:useBean id="rst" scope="page" class="com.mlh.dao.sqldao"/>
<%
String year=request.getParameter("year");
//获得某年按月份分组的总销售额的SQL语句
String strSql="select sum(je) as sumje,month(date) as xsmonth from tb_sell"+
" where year(date)='"+year+"' group by month(date)";
ResultSet rs=rst.getResult(strSql);
int counts=0;
if(!rs.next()){
out.println("<script language='javascript'>alert('"+year+"年没有销售记录');"+
"window.location.href='main.jsp';</script>");
}
else{//获得某年按销售月份分组的总记录数
String strCount="select count(*) from ( "+strSql+" ) as aa";
ResultSet rs1=rst.getResult(strCount);
if(rs1.next())
counts=rs1.getInt(1);
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="820" border="1" align="center" cellpadding="0"cellspacing="0" bordercolor="#FFFFFF" bordercolorlight="#9CA6C6" bordercolordark="#CCE3FF" height="63">
<tr align="center" bgcolor="#FFFFC1">
<td height="50" bgcolor="#FFFFC1">
<%
if (counts>0){
%>
<!--定义一个对象该对象名为chart-->
<object classid="clsid:3A2B370C-BA0A-11D1-B137-0000F8753F5D" name="chart" width="100%" height="255">
</object>
<%
for(int j=1;j<=counts;j++){ //循环从1循环到counts
%>
<script language="javascript">
charts("pillar"); //调用charts()函数
function charts(type){
if (type=="line"){
chart.chartType=3;
//chartType是对象chart的属性:表示图形类型
}
if (type=="pillar" ){
chart.chartType=1;
}
chart.ColumnCount=1; //ColumnCount是对象chart的属性:表示设置与图表关联的当前数据网格中的列数。
chart.Title="<%=year%>年销售额分析表"; //图表标题
chart.rowcount=<%=counts%>; //rowcount属性:数据行个数。
chart.row=<%=j%>; //row属性:当前数据行
chart.rowlabel="<%=rs.getString("xsmonth")%>月"; //rowlabel属性:返回/设置一个数据标签,该标签用来标识图表中当前数据点。横坐标值
chart.Data=<%=rs.getString("sumje")%>; //Data属性:当前数据点的值。纵坐标值
chart.Footnote="注:纵坐标为销售额,单位为(元) ;空缺的月份没有销售额"
}
</script>
<%
rs.next();
}
%>
</td>
</tr>
</table>
<table width="97%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="26" align="center">
<form name="form1" method="post" action="">
<input type="button" class="btn_grey" onClick="charts('pillar')" value="柱状图分析">
<input type="button" class="btn_grey" onClick="charts('line')" value="线性图分析">
</form> </td>
</tr>
</table>
<% } %>
<div align="center">
</div>
</body>
</html> 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询