直接是在jsp页面操作。代码写的有点乱:
<%@ page language="java"
import="java.io.*,
java.awt.*,
java.sql.*,
java.text.*,
java.util.*,
org.jfree.data.*,
org.jfree.chart.*,
org.jfree.chart.plot.CategoryPlot,
org.jfree.chart.axis.ValueAxis,
org.jfree.chart.plot.CategoryPlot,
org.jfree.chart.plot.PlotOrientation,
org.jfree.data.category.CategoryDataset,
org.jfree.chart.title.TextTitle,
org.jfree.chart.plot.PlotOrientation,
org.jfree.data.general.DatasetUtilities,
org.jfree.chart.plot.CategoryPlot,
org.jfree.chart.renderer.category.BarRenderer3D,
org.jfree.chart.axis.CategoryAxis"
pageEncoding="GB2312"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%
if(request.getParameter("viewSubmit")!=null)
{
%>
<jsp:useBeanid ="db" scope="page" class="hnccbean.DBConnection"/>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>view_report</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
</head>
<%
long ACDCALLS=0;
long ABNCALLS=0;
long PERCENT_SERV_LVL_SPL=0;
long TI_AUXOTHERTIME=0;
long AVG_ABANDON_TIME=0;
long I_ACWTIME=0;
long AVG_ANSWER_SPEED=0;
long AVG_TALK_TIME_IN=0;
float r1=0.00f;
float r2=0.00f;
float r3=0.00f;
long tqqzl=0;
long tjtzl=0;
long tfqzl=0;
long tydzl=0;
String strwhere=new String("");
String startDate = request.getParameter("start_date");//开始日期
String endDate = request.getParameter("end_date");//截止日期
String shour = request.getParameter("shour");
String ehour = request.getParameter("ehour");
String type = request.getParameter("type");//技能组类型
String hour = request.getParameter("hour");//选择特定时间
if(startDate!=null)
strwhere = " and convert(varchar,a.STARTTIME,112)>='"+startDate+"'";
if(endDate!=null)
strwhere += " and convert(varchar,a.STARTTIME,112)<='"+endDate+"'";
if(hour !=null && !"".equals(hour)){
strwhere += " and convert(int,convert(char(2),a.STARTTIME,108))="+Integer.parseInt(hour)+"";
}
if(type!=null){
if(type.equals("00")!=true){
strwhere += " and a.SPLIT='"+type+"'";
}
}
String splitName = "";
if (type.equals("00")==true) {
splitName = "全部技能组";
}
if (type.equals("11")==true) {
splitName = "世界风VIP";
}
if (type.equals("12")==true) {
splitName = "世界风普通";
}
if (type.equals("14")==true) {
splitName = "UP新势力";
}
if (type.equals("15")==true) {
splitName = "如意通";
}
if (type.equals("16")==true) {
splitName = "其它";
}
if (type.equals("20")==true) {
splitName = "投诉组";
}
if (type.equals("34")==true) {
splitName = "3G专席";
}
if (type.equals("32")==true) {
splitName = "固网专席";
}
java.text.DecimalFormat df =new java.text.DecimalFormat("0.00");
JFreeChart chart = null;
String[] rowKeys = new String[]{"呼入量","接通量"};
SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
int days = 0;
GregorianCalendar calender = new GregorianCalendar();
String[] columnKeys =null;
double[][] data = null;
try {
java.util.Date date1 = format.parse(startDate);
java.util.Date date2 = format.parse(endDate);
calender.setTime(date1);
days = (int) ((date2.getTime() - date1.getTime()) / 86400000);
if((hour ==null ||"".equals(hour))&& days==0){
columnKeys = new String[] {"00","01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23"};
data = new double[2][24];
}else{
columnKeys = new String[days+1];
data = new double[2][days+1];
}
columnKeys[0] = startDate.substring(4);
for (int i = 1; i <= days; i++) {
calender.add(5, 1);
columnKeys[i]=format.format(calender.getTime()).substring(4);
}
String query = "";
Statement st = db.getStatement();
if((hour ==null || "".equals(hour))&& days==0){//24个小时都查询出来
query = "select convert(char(2),a.STARTTIME,108) htime,sum(b.incalls),sum(a.ACDCALLS)from hsplit a,rpt_vdn_incalls b where a.SPLIT=b.split and a.ACDCALLS>0 and a.STARTTIME=b.starttime and a.SPLIT in ('11','12','14','15','16','20','28','32','34') ";
query=query+strwhere + "group by convert(char(2),a.STARTTIME,108) order by htime";
}else{//起始日期和截止日期之间每天的某个小时
query = "select convert(varchar,a.STARTTIME,112) sdate,sum(b.incalls),sum(a.ACDCALLS)from hsplit a,rpt_vdn_incalls b where a.SPLIT=b.split and a.ACDCALLS>0 and convert(varchar,a.STARTTIME,112)=convert(varchar,b.starttime,112) and convert(int,convert(char(2),a.STARTTIME,108))= convert(int,convert(char(2),b.starttime,108)) and a.SPLIT in ('11','12','14','15','16','20','28','32','34') ";
query=query+strwhere + " group by convert(varchar,a.STARTTIME,112) order by sdate";
}
//out.println(query + "<br>");
ResultSet rs =null;
try {
rs = st.executeQuery(query);
int count = 0;
while(rs.next()) {
for (int n=0 ; n<columnKeys.length ; n++) {
if (columnKeys[n].equals(rs.getString(1).substring(4)) == true) {
data[0][n] = new Integer(rs.getString(2)).doubleValue();
data[1][n] = new Integer(rs.getString(3)).doubleValue();
continue;
}
}
}
} catch (SQLException e) {
out.println("组合出错了");
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
if(rs !=null)
rs.close();
if(st !=null)
st.close();
if(db !=null)
db.close();
}
//-----------------以上都是准备数据。这个数据是从数据库里面取的
//得到数据集
CategoryDataset dataset = DatasetUtilities.createCategoryDataset(
rowKeys, columnKeys, data);
//得到图形对象:ChartFactory.createBarChart3D(,,,,,,,);里面的内容依次表示:图形标题;目录轴的显示标签,数值轴的显示标签,数据集,图标方向,是否显示图例(对于简单的柱状图必须是false),是否生成工具,是否生成URL链接
chart = ChartFactory.createBarChart3D(splitName + "话务量统计", "时间", "话务量", dataset,
PlotOrientation.VERTICAL, true, false, false);
//获得图标区域对象
CategoryPlot plot = chart.getCategoryPlot();
//获得X轴对象
CategoryAxis domainAxis = plot.getDomainAxis();
//获取图标区域样式对象
BarRenderer3D renderer = new BarRenderer3D();
//Y轴对象
ValueAxis rAxis = plot.getRangeAxis();
//显示字体渲染,使显示字体内容不模糊,最好把字体设置在12以上
chart.getRenderingHints().put(
RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_OFF
);
/*----------设置标题字体--------------------------*/
TextTitle textTitle = chart.getTitle();
textTitle.setFont(new Font("黑体", Font.PLAIN, 20));
/*------设置X轴坐标上的文字-----------*/
domainAxis.setTickLabelFont(new Font("sans-serif",Font.PLAIN,11));
/*------设置X轴的标题文字------------*/
domainAxis.setLabelFont(new Font("宋体",Font.PLAIN,12));
/*------设置Y轴坐标上的文字-----------*/
rAxis.setTickLabelFont(new Font("sans-serif",Font.PLAIN,12));
/*------设置Y轴的标题文字------------*/
rAxis.setLabelFont(new Font("黑体",Font.PLAIN,12));
//解决X轴下方字体乱码
chart.getLegend().setItemFont(new Font("宋体",Font.PLAIN,12));
renderer.setItemMargin(0.0);
//显示每个柱的数值,并修改该数值的字体属性(如果柱体太窄了的话。数值是现实不出来的)
renderer.setItemLabelGenerator(new org.jfree.chart.labels.StandardCategoryItemLabelGenerator());
renderer.setItemLabelFont(new Font("黑体",Font.BOLD,12));//12号黑体加粗
renderer.setItemLabelPaint(java.awt.Color.black);//字体为黑色
renderer.setItemLabelsVisible(true);
//把图像区域样式注入到图形区域对象中区
plot.setRenderer(renderer);
%>
<body>
<%
try
{
int width=600;
if(days >7 && days<=10){
width =800;
}
if(days>10){
width=900;
}
//输出
ChartUtilities.writeChartAsJPEG(response.getOutputStream(), chart, width, 480);
response.getOutputStream().flush();
response.getOutputStream().close();
out.clear();
out = pageContext.pushBody();
}
catch (Exception e)
{
out.println("输出出错了");
e.printStackTrace();
}
} catch (Exception e) {
out.println("最外面出错了");
e.printStackTrace();
}
}
%>
<input type="button" value="back">
</body>
</html>