页面:
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <%@ include file="/WEB-INF/jsp/common/config.jsp"%> <%@ include file="/WEB-INF/jsp/common/jspenv2.jsp"%> <html> <head> <title>各系统课程统计</title> </head> <body> <div class="easyui-panel" title="高级搜索" data-options="iconCls:'icon-save',collapsible:true"> <div class="panel-body panel-body-noheader panel-body-noborder" title="" style="position: relative;"> <div style="margin: 0px auto; margin-left: 5px;"> <div> 外系统名称:
<select id="outSystemSign"> <c:if test="${not empty kpOutSystemList }"> <c:forEach items="${kpOutSystemList }" var="sa"> <option value="${sa.outSystemSign }">${sa.outSystemName }</option> </c:forEach> </c:if> </select> 创建时间:
<input id="startTime" name="startTime" class="Wdate" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" realvalue=""> 至
<input id="endTime" name="endTime" class="Wdate" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})"> <a id="search" class="easyui-linkbutton l-btn" iconcls="icon-search" href="#" onclick="goShowData();">统计</a> </div> </div> </div> </div> <div> <img id="imged" src=""> </div> <br> </body> <script type="text/javascript"> $(function() { //查询统计数据 goShowData(); });
//查询统计数据 function goShowData(){ $.jBox.tip('正在加载...','loading'); var outSystemSign= $("#outSystemSign").val() ; var outSystemName = $("#outSystemSign").find("option:selected").text(); var startTime= $("input[name='startTime']").val(); var endTime= $("input[name='endTime']").val(); //将图片地址赋值 $("#imged").attr("src","<c:url value='/company/view.do?op=getOutSystemCompanyCount&outSystemSign=" +outSystemSign+"&outSystemName="+outSystemName+"&startTime="+startTime+"&endTime="+endTime+"&random="+Math.random()+"'/>"); $.jBox.closeTip(); } </script> </html>
后台方法:
/** * Description: 统计各系统发票数据总数、各类发票数量———个人发票 */ public ActionForward getOutSystemInvoiceNumber(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception { String outSystemSign = RequestHandler.getString(request, "outSystemSign");//外系统查询条件 Date startTime = RequestHandler.getDate(request, "startTime"); Date endTime = RequestHandler.getDate(request, "endTime"); Invoice invoice = new Invoice(); invoice.setOutSystemSign(outSystemSign); invoice.setEndTime(endTime); invoice.setStartTime(startTime); List<Invoice> invoiceList = new ArrayList<Invoice>(); if(null != outSystemSign){ invoiceList = invoiceFacade.getOutSystemInvoiceNumberByDate(invoice); }else{ invoiceList = invoiceFacade.getOutSystemInvoiceNumber(invoice); } response.setContentType("text/html"); //总试卷数 int totalInvoiceNumber = invoiceFacade.getInvoiceNumber(invoice);//发票总数量 int totaleInvoiceNumber = 0;//电子发票总数 int totalOrdInvoiceNumber= 0;//纸质发票总数 int totalVatInvoiceNumber = 0;//增值税发票总数 // 绘图数据集 DefaultCategoryDataset dataSet = new DefaultCategoryDataset(); if(null != outSystemSign){ for (Invoice char : invoiceList) { dataSet.addValue(char.getInvoiceNumber(), "发票数量", char.getCreateDateStr()); } JFreeChart chart = ChartFactory.createLineChart( //--------------折线图-------------- "发票数量总计:" + totalInvoiceNumber,//图的标题 "申请日期", //x轴标题 "发票数量(个)", //y轴标题 dataSet,//数据点 PlotOrientation.VERTICAL, true, true, false); // 字体清晰 chart.setTextAntiAlias(false); // 设置背景颜色 chart.setBackgroundPaint(Color.WHITE); // 设置图标题的字体 Font font = new Font("隶书", Font.BOLD, 25); chart.getTitle().setFont(font); // 设置面板字体 Font labelFont = new Font("SansSerif", Font.TRUETYPE_FONT, 12); // 设置图示的字体 chart.getLegend().setItemFont(labelFont); CategoryPlot categoryplot = (CategoryPlot) chart.getPlot(); // x轴 // 分类轴网格是否可见 categoryplot.setDomainGridlinesVisible(true); // y轴 //数据轴网格是否可见 categoryplot.setRangeGridlinesVisible(true); categoryplot.setRangeGridlinePaint(Color.WHITE);// 虚线色彩 categoryplot.setDomainGridlinePaint(Color.WHITE);// 虚线色彩 categoryplot.setBackgroundPaint(Color.lightGray);// 折线图的背景颜色 // 设置轴和面板之间的距离 // categoryplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D)); // 横轴 x CategoryAxis domainAxis = categoryplot.getDomainAxis(); domainAxis.setLabelFont(labelFont);// 轴标题 domainAxis.setTickLabelFont(labelFont);// 轴数值 domainAxis.setMaximumCategoryLabelLines(15);//标题行数,每个字显示一行 domainAxis.setMaximumCategoryLabelWidthRatio(1.0f); //每个标题宽度,控制为1个字的宽度 domainAxis.setLabelPaint(Color.BLUE);//轴标题的颜色 domainAxis.setTickLabelPaint(Color.BLUE);//轴数值的颜色 // 横轴 lable 的位置 横轴上的 Lable 45度倾斜 DOWN_45 domainAxis.setCategoryLabelPositions(CategoryLabelPositions.STANDARD); // 设置距离图片左端距离 domainAxis.setLowerMargin(0.0); // 设置距离图片右端距离 domainAxis.setUpperMargin(0.0); // 纵轴 y NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis(); numberaxis.setLabelFont(labelFont); numberaxis.setTickLabelFont(labelFont); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); numberaxis.setAutoRangeIncludesZero(true); // 获得renderer LineAndShapeRenderer lineandshaperenderer = (LineAndShapeRenderer) categoryplot .getRenderer(); lineandshaperenderer.setBaseShapesVisible(true); // series 点(即数据点)可见 lineandshaperenderer.setBaseLinesVisible(true); // series 点(即数据点)间有连线可见 // 显示折点数据 lineandshaperenderer .setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); lineandshaperenderer.setBaseItemLabelsVisible(true); // 向客户端输出生成的图片 ChartUtilities.writeChartAsJPEG(response.getOutputStream(), 1.0f,chart,
invoiceList.size() <= 10 ? 1000 : invoiceList.size() * 80, 650, null); }else{ for (Invoice char : invoiceList) { dataSet.addValue(char.geteInvoiceNumber(), "电子发票数量", char.getOutSystemName()); dataSet.addValue(char.getOrdInvoiceNumber(), "纸质发票数量", char.getOutSystemName()); dataSet.addValue(char.getVatInvoiceNumber(), "增值税发票数量", char.getOutSystemName()); dataSet.addValue(char.getInvoiceNumber(), "发票总数量", char.getOutSystemName()); totaleInvoiceNumber += char.geteInvoiceNumber(); totalOrdInvoiceNumber += char.getOrdInvoiceNumber(); totalVatInvoiceNumber += char.getVatInvoiceNumber(); } JFreeChart chart = ChartFactory.createBarChart( //--------------柱状图-------------- "发票数量总计:" + totalInvoiceNumber +"电子发票数量总计:" + totaleInvoiceNumber +
"纸质发票数量总计:" + totalOrdInvoiceNumber +"增值税发票总计:"+totalVatInvoiceNumber, //图的标题 "所属系统", //x轴标题 "发票数量(个)", //y轴标题 dataSet,//数据点 PlotOrientation.VERTICAL, true, true, false); //字体清晰 chart.setTextAntiAlias(false); // 设置背景颜色 chart.setBackgroundPaint(Color.WHITE); // 设置图标题的字体 Font font = new Font("隶书", Font.BOLD, 25); chart.getTitle().setFont(font); // 设置面板字体 Font labelFont = new Font("SansSerif", Font.TRUETYPE_FONT, 12); // 设置图示的字体 chart.getLegend().setItemFont(labelFont); CategoryPlot categoryplot = (CategoryPlot) chart.getPlot(); // x轴 // 分类轴网格是否可见 categoryplot.setDomainGridlinesVisible(true); // y轴 //数据轴网格是否可见 categoryplot.setRangeGridlinesVisible(true); categoryplot.setRangeGridlinePaint(Color.WHITE);// 虚线色彩 categoryplot.setDomainGridlinePaint(Color.WHITE);// 虚线色彩 categoryplot.setBackgroundPaint(Color.lightGray);// 折线图的背景颜色 // 设置轴和面板之间的距离 categoryplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D)); // 横轴 x CategoryAxis domainAxis = categoryplot.getDomainAxis(); domainAxis.setLabelFont(labelFont);// 轴标题 domainAxis.setTickLabelFont(labelFont);// 轴数值 domainAxis.setMaximumCategoryLabelLines(15);//标题行数,每个字显示一行 domainAxis.setMaximumCategoryLabelWidthRatio(1.0f); //每个标题宽度,控制为1个字的宽度 domainAxis.setLabelPaint(Color.BLUE);//轴标题的颜色 domainAxis.setTickLabelPaint(Color.BLUE);//轴数值的颜色 // 横轴 lable 的位置 横轴上的 Lable 45度倾斜 DOWN_45 domainAxis.setCategoryLabelPositions(CategoryLabelPositions.STANDARD); // 设置距离图片左端距离 domainAxis.setLowerMargin(0.005); // 设置距离图片右端距离 domainAxis.setUpperMargin(0.005); // 纵轴 y NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis(); numberaxis.setLabelFont(labelFont); numberaxis.setTickLabelFont(labelFont); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); numberaxis.setAutoRangeIncludesZero(true); BarRenderer barrenderer = new BarRenderer(); barrenderer.setMaximumBarWidth(0.1); barrenderer.setMinimumBarLength(0.1); barrenderer.setBaseItemLabelsVisible(true); barrenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); barrenderer.setSeriesItemLabelsVisible(0, Boolean.TRUE);; // series 点(即数据点)可见 barrenderer.setBaseItemLabelFont(new Font("隶书",Font.PLAIN,14)); categoryplot.setRenderer(barrenderer); // 向客户端输出生成的图片 ChartUtilities.writeChartAsJPEG(response.getOutputStream(), 1.0f,chart,
invoiceList.size() <= 1 ? 1000 : invoiceList.size() * 150, 650, null); } return null; }