这个是一个柱状和曲线结合的图形
<%@ 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.NumberAxis,
org.jfree.chart.renderer.category.LineAndShapeRenderer,
org.jfree.chart.plot.DatasetRenderingOrder,
org.jfree.chart.labels.ItemLabelAnchor,
org.jfree.chart.labels.ItemLabelPosition,
org.jfree.ui.TextAnchor,
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[]{"请求总量","接通总量","20秒应答量"};
String[] columnKeys =null;
double[][] data = null;
String[] rowKeys1 = new String[]{"人工接通率","服务水平","服务水平下线"};
String[] columnKeys1 =null;
double[][] data1 = null;
SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
int days = 0;
GregorianCalendar calender = new GregorianCalendar();
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);
columnKeys = new String[days+1];
data = new double[3][days+1];
columnKeys1 = new String[days+1];
data1 = new double[3][days+1];
columnKeys[0] = startDate.substring(4);
columnKeys1[0] = startDate.substring(4);
for (int i = 1; i <= days; i++) {
calender.add(5, 1);
columnKeys[i]=format.format(calender.getTime()).substring(4);
columnKeys1[i]=format.format(calender.getTime()).substring(4);
}
String query = "";
Statement st = db.getStatement();
ResultSet rs =null;
query = "select convert(varchar,a.STARTTIME,112) sdate,sum(b.incalls),sum(a.ACDCALLS),sum(a.ACDCALLS*a.PERCENT_SERV_LVL_SPL) 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(varchar,a.STARTTIME,112) order by sdate";
//out.println(query + "<br>");
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();
data[2][n] = new Integer(rs.getString(4))/100;
data1[0][n] = new Integer(rs.getString(3)).doubleValue()/new Integer(rs.getString(2)).doubleValue();
data1[1][n] = new Integer(rs.getString(4)).doubleValue()/100/new Integer(rs.getString(2)).doubleValue();
data1[2][n] = 0.7D;
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();
}
//数据集1(柱状)
CategoryDataset dataset = DatasetUtilities.createCategoryDataset(
rowKeys, columnKeys, data);
//数据集2(曲线)
CategoryDataset dataset1 = DatasetUtilities.createCategoryDataset(
rowKeys1, columnKeys1, data1);
//创建一个chart对象
chart = ChartFactory.createBarChart3D(splitName + "10010热线整体情况统计("+startDate.substring(0,6)+")", "时间", "话务量", dataset,
PlotOrientation.VERTICAL, true, false, false);
// 图像区域对象
CategoryPlot plot = chart.getCategoryPlot();
//获取数据轴X轴对象
CategoryAxis domainAxis = plot.getDomainAxis();
domainAxis.setLowerMargin(0.02D);//数据轴左边距
domainAxis.setUpperMargin(0.02D);//右边距
//获取图像区域样式对象
BarRenderer3D renderer = new BarRenderer3D();
//获取Y轴对象(默认的是Y轴左边对象)
ValueAxis rAxis = plot.getRangeAxis();
rAxis.setLowerMargin(0.02D);//数据轴左边距
rAxis.setUpperMargin(0.02D);//右边距
//解决字体模糊
chart.getRenderingHints().put(
RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_OFF
);
//获取数据轴对象
NumberAxis numberaxis3 = new NumberAxis("百分比");
numberaxis3.setNumberFormatOverride(NumberFormat.getPercentInstance());//设置风格以百分数
numberaxis3.setAutoRange(false);
numberaxis3.setLowerMargin(0.02D);//数据轴左边距
numberaxis3.setUpperMargin(0.02D);//右边距
//把该数据轴放置到右边的Y轴
plot.setRangeAxis(1, numberaxis3);
plot.setDataset(1, dataset1);//设置数据集索引
plot.mapDatasetToRangeAxis(1,1);//将该索引映射到axis 第一个参数指数据集的索引,第二个参数为坐标轴的索引
//曲线样式对象
LineAndShapeRenderer lineandshaperenderer = new LineAndShapeRenderer();
//第一条曲线样式
lineandshaperenderer.setSeriesPaint(0, new Color(255,0,255));//桃红
// 第二条曲线样式
lineandshaperenderer.setSeriesPaint(1, new Color(0,0,255));//墨绿6
//第三条曲线样式
lineandshaperenderer.setSeriesPaint(2, Color.BLACK);//墨绿6
lineandshaperenderer.setShapesVisible(true);
//设置某坐标轴索引上数据集的显示样式
plot.setRenderer(1, lineandshaperenderer);
//设置2个图像的显示顺序:DatasetRenderingOrder.FORWARD:表示后者放在前面; DatasetRenderingOrder.REVERSE:表示后者放在后面
plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
/*----------设置标题字体--------------------------*/
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.setItemLabelsVisible(true);
//这一部分很重要。当柱体太小时候。数值不能显示,那么只有改边显示的位置
renderer.setBaseItemLabelGenerator(new org.jfree.chart.labels.StandardCategoryItemLabelGenerator());//显示每个柱的数值
renderer.setBaseItemLabelsVisible(true);
//设置不能在柱子上正常显示的那些数值的显示方式,将这些数值显示在柱子外面
ItemLabelPosition itemLabelPositionFallback=new ItemLabelPosition(
ItemLabelAnchor.OUTSIDE12,TextAnchor.BASELINE_LEFT,
TextAnchor.HALF_ASCENT_LEFT,-0.0D);
//设置当不能正常显示柱状值的时候
renderer.setPositiveItemLabelPositionFallback(itemLabelPositionFallback);
renderer.setNegativeItemLabelPositionFallback(itemLabelPositionFallback);
plot.setRenderer(renderer);
%>
<body>
<%
try
{
int width=600;
if(days >7 && days<=10){
width =800;
}
if(days>10&& days<=20){
width=900;
}
if(days>20 && days<=25){
width=1100;
}if(days>25){
width=1200;
}
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>