Jqpivottable实现多维分析
<%@ page language="java" pageEncoding="UTF-8"%><%@taglib uri="/struts-tags" prefix="s"%><%@ include file="common/header.jsp"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><title>浙江省电力公司作业项目安全风险管控系统</title><link href="${root}/css/PivotTable.css" rel="stylesheet" type="text/css" /> <script src="${root}/scripts/jquery-1.6.4.min.js" type="text/javascript"></script> <script src="${root}/scripts/jquery.ui.core.js" type="text/javascript"></script> <script src="${root}/scripts/jquery.ui.widget.js" type="text/javascript"></script> <script src="${root}/scripts/jquery.ui.mouse.js" type="text/javascript"></script> <script src="${root}/scripts/jquery.ui.draggable.js" type="text/javascript"></script> <script src="${root}/scripts/jquery.ui.droppable.js" type="text/javascript"></script> <script src="${root}/scripts/jquery.ui.sortable.js" type="text/javascript"></script> <script src="${root}/scripts/json2.js" type="text/javascript"></script> <script src="${root}/scripts/number-functions.js" type="text/javascript"></script> <script src="${root}/scripts/jqPivotTable.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function(){ $("#pivotT").pivottable({ urldata: "jxplan/jpt.action", //URL data from AJAX urlfields: "500.jsp", //jxplan/jpt.action//URL fields catalog from AJAX (obsolete in v 1.1) table: "jx_plan_item", columns: ["电压等级","属性","风险等级"], rows: ["是否计划外", "计划类型"], filters: ["风险类型"], datafields: "risk_level_count", op: "COUNT" //sum or count }); }) </script></head><body><form id="frm1" name="frm1" method="post" action=""><div name="code">/** * 多维分析 * @return */public String jpt()throws Exception{//查询结果集List<JxPlanItemMultidimAnalysis> list = jxPlanItemServiceImpl.list(null);//定义一些常用的符号final String lbb="{",rbb="}",dq=""",colone=":",lmb="[",rmb="]",comma=",";StringBuffer sb= new StringBuffer();sb.append(lbb).append(dq).append("items").append(dq).append(colone).append(lmb);for (JxPlanItemMultidimAnalysis j : list) {sb.append(lbb);sb.append(dq).append("电压等级").append(dq).append(colone).append(dq).append(j.getVolLevel()==null?"":j.getVolLevel()).append(dq);//sb.append(comma);sb.append(dq).append("是否计划外").append(dq).append(colone).append(dq).append(ValidateUtil.matchString(j.getIsOut(), String.valueOf(true))?"是":"否").append(dq);sb.append(comma);sb.append(dq).append("计划类型").append(dq).append(colone).append(dq).append(j.getPlanType()==null?"":j.getPlanType()).append(dq);sb.append(comma);sb.append(dq).append("属性").append(dq).append(colone).append(dq).append(j.getProjectAttribute()==null?"":j.getProjectAttribute()).append(dq);sb.append(comma);sb.append(dq).append("风险类型").append(dq).append(colone).append(dq).append(j.getRiskType()==null?"":j.getRiskType()).append(dq);sb.append(comma);sb.append(dq).append("风险等级").append(dq).append(colone).append(dq).append(j.getRiskLevel()==null?"":j.getRiskLevel()).append(dq);sb.append(comma);sb.append(dq).append("risk_level_count").append(dq).append(colone).append(dq).append(j.getRiskLevelCount()).append(dq);sb.append(rbb).append(comma);}sb.deleteCharAt(sb.length()-1);sb.append(rmb).append(rbb);jsonString = sb.toString();return SUCCESS;}
?
? 这里我们将获得的结果转成json格式的字符串,返回给前端页面。
? 这里我没有直接用JSONObject或者JSONArray对象来转是因为我的字段需要中文名称,便于在页面显示。
?