Highchart應用封裝

*********************************************************************************************************
*******************************************jsp頁面:staffRiskStat.jsp************************************
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="struts" uri="/struts-tags" %>

<!--引入path java中的path和js中的path-->
<%@include file="/modules/comm/loadingData.jsp" %>
<%@include file="/common/path_header.jsp" %>
<%@include file="/common/jqgrid_header.jsp" %>

<!--顯示對話框-->
<script type="text/javascript" src="${path}/script/common/rims.js"></script>

<script src="<%=path%>/script/hightcharts3.0.10/highcharts.js"></script>
<script src="<%=path%>/script/hightcharts3.0.10/modules/exporting.js"></script>
<!--myChart爲封裝好的js文件-->
<script src="<%=path%>/script/common/myChartTheme.js"></script>
<script src="<%=path%>/script/common/myChart.js"></script>

<!--dwr-->
<script type="text/javascript" src="<%=path%>/dwr/engine.js"></script>
<script type="text/javascript" src="<%=path%>/dwr/util.js"></script>
<script type="text/javascript" src="<%=path%>/dwr/interface/dwrStuffRiskStat.js"></script>

<!--選擇用戶-->
<script type="text/javascript" src="<%=path%>/script/common/uIUtiltyCommon.js"></script>

<style type="text/css">
.td-border-class
{
border: 1px solid #000000;
border-collapse:collapse;
background-color: #E8F7FA;
}

.td-class
{
border: 1px solid #E5E5E5;
border-collapse:collapse;
}

.stat-module-title
{
height: 30px;
font-size: 20px;
font-weight: bold;
border: 1px solid #E5E5E5;
vertical-align: bottom;
text-align:center;
}

.bpmSelectUser {
background-color: transparent;
background-image: url("/htsc.abms/modules/comm/img/user_add.gif");
background-repeat: no-repeat;
border: medium none;
height: 20px;
overflow: hidden;
vertical-align: middle;
cursor: pointer;
width: 20px;
}

#userName
{
width:400px;
}

.countBtn
{
background: url("/htsc.abms/modules/images/button.png");
background-color:#2CB1EC;
color:#ffffff;
font-size: 14px;
cursor: pointer;
width:70px;
}

.total-class{
min-width:500px;
min-height: 400px;
}

.detail-class{
min-width:1000px;
min-height: 400px;
}

#severityTotalShow
{
font-size: 24px;
font-weight:bolder;
background: url('../../../../images/severitybg.jpg') repeat;
}
</style>

<table align="center" width="1000" class="td-border-class">
<thead>
<tr>
<td colspan="2" class="td-class" height="40" bgcolor="#BFDAEF">
   
請選擇人員:
<input id="userName" value="" name="" readonly="true"/>
<input id="selectUser" class="bpmSelectUser" type="button" onclick="selectUsers();"/>
   
<input class="countBtn" type="button" value="分析" onclick="count();">
</td>
</tr>
</thead>

<tbody>
<!--風險發生頻率總體視圖-->
<tr>
<td class="stat-module-title" class="td-class" colspan="2"> 風險發生總體視圖</td>
</tr>
<tr>
<td width="500" class="td-class">
<div id="typesProblemTotal" class="total-class"></div>
</td>
<td width="500" class="td-class">
<div id="problemRectifyTotal" class="total-class"></div>
</td>
</tr>
<tr>
<td width="500" class="td-class">
<div id="problemSeverityTotal" class="total-class"></div>
</td>
<td width="500" class="td-class">
<div id="severityTotalShow" class="total-class">
<br>
<br>
<table align="center" height ="300" width="300" bgcolor="#E7F6F9">
<tr><td colspan="2" align="center" bgcolor="#BFDAEF">具體情況如下:</td></tr>
<tr bgcolor="#D3E9F6">
<td align='center' width='150'>嚴重問題:</td>
<td align='center' width='150'>0個</td>
</tr>
<tr bgcolor="#D3E9F6">
<td align='center' width='150'>一般問題:</td>
<td align='center' width='150'>0個</td>
</tr>
<tr bgcolor="#D3E9F6">
<td align='center' width='150'>輕微問題:</td>
<td align='center' width='150'>0個</td>
</tr>
</table>
</div>
</td>
</tr>

<!--風險發生頻率-->
<tr>
<td colspan="2" class="td-class">
<div id="riskFrequency" class="detail-class" ></div>
<div>
<table id ="riskFrequencyGrid"></table>
</div>
</td>
</tr>

<!--風險發生偏好-->
<tr>
<td colspan="2" class="td-class">
<div id="riskPreferences" class="detail-class"></div>
<div>
<table id ="riskPreferencesGrid"></table>
</div>
</td>
</tr>

<!--風險整改情況-->
<tr>
<td colspan="2" class="td-class">
<div id="problemRectify" class="detail-class"></div>
<div>
<table id ="problemRectificationGrid"></table>
</div>
</td>
</tr>

<!--風險發生程度明細-->
<tr>
<td colspan="2" class="td-class">
<div id="riskSeverity" class="detail-class"></div>
<div>
<table id ="riskSeverityGrid"></table>
</div>
</td>
</tr>
</tbody>
</table>
<input type="hidden" id="USER_ID">
<input type="hidden" id="REPORT_ID">
<input type="hidden" id="RISK_TYPE">
<input type="hidden" id="REFORM_STATUS">
<input type="hidden" id="SEVERITY_LEVEL">

<script type="text/javascript">

// 選擇用戶
function selectUsers()
{
// 選擇的用戶
var _selectedUsers = [];

// 篩選條件
var modalDialogParam={};

// 是否單選
modalDialogParam["singleSelect"] = true;

var newSelectUsers = selectUser(_selectedUsers,modalDialogParam);

// 返回有用戶
if( newSelectUsers!=undefined )
{
var user = newSelectUsers[0];

// 判斷選擇人
if(null==user){
return;
}

// 將用戶添加到查詢作爲輸入參數
_selectedUsers.push(user);

// Ajax後臺查詢用戶的部門信息
$.ajax({
type: "POST",
data:{"userId":user.UUID},
url: path+"/org/getOrgInfoByUserId.do",
async: false,
dataType:'json',
success: function(org){
if( org!=undefined&&org!=null&&org.orgId!=undefined&&org.orgId!=null )
{
$("#userName").val(org.orgName +" "+user.DUTY +" "+user.REALNAME);
$("#userName").attr('name',user.UUID);
}
}
});
}
}

// 初始化加載
count();

// 統計函數
function count(){

// 拿到稽查人員的用戶Id
var userId= $("#userName").attr("name");

// 用戶ID
if(userId == undefined || userId == null || userId =="")
{
noData_pie('typesProblemTotal');
noData_pie('problemRectifyTotal');
noData_pie('problemSeverityTotal');
noData_column('riskFrequency');
noData_column('riskPreferences');
noData_column('problemRectify');
noData_column('riskSeverity');
// document.getElementById("severityTotalShow").innerHTML="";
return;
}

// 封裝參數
var o = {
id:userId
}

// 顯示加載
createDiv();

// 風險類型彙總
dwrStuffRiskStat.queryRiskTypeTotal(o,function(data){
myChart("typesProblemTotal",data,function(event){

});

// 加載完成移出
removeDiv();
});

// 風險整改彙總
dwrStuffRiskStat.queryRiskRectifyTotal(o,function(data){
myChart("problemRectifyTotal",data,function(event){

});
});


// 風險嚴重程度彙總
dwrStuffRiskStat.queryRiskSeverityTotal(o,function(data){
myChart("problemSeverityTotal",data,function(event){

});

document.getElementById("severityTotalShow").innerHTML="";

// 拿到系列值
var names = xNames(data);

// 拿到系列數據
var counts = data['seriesList'][0]['chartData'];

var severityCount =0;
var sum = 0;
var text ="<table align='center' height ='270' width='300' bgcolor='#E7F6F9'>"
+"<tr><td colspan='2' align='center' bgcolor='#BFDAEF'>具體情況如下:</td></tr>";
for(var i=0;i<names.length;i++)
{
text += "<tr bgcolor='#D3E9F6'>";
text +="<td align='center' width='150'>"+names[i]+"問題:</td>";

if(names[i]=='嚴重')
{
text +="<td align='center' width='150'><font color='red'>"+counts[i]+"</font>個</td>";
severityCount = counts[i];
}else{
text +="<td align='center' width='150'>"+counts[i]+"個</td>";
}

text += "</tr>";
sum += counts[i];
}

text += "</table>";

var severity="";
if(severityCount*100/sum>30)
{
severity = "<font color='red'>高</font>";
}
else
{
severity = "中";
}

var textTitle= "<br><center>風險發生等級爲: "+severity+"</center><br>";

document.getElementById("severityTotalShow").innerHTML=textTitle+text;
});

// 風險發生頻率
dwrStuffRiskStat.queryRiskFrequency(o,function(data){
myChart("riskFrequency",data,function(event){
// 清空參數
clear();

// 拿到Id
var id = event.point.id;

$("#USER_ID").val(userId);

$("#REPORT_ID").val(id);

// 加載表格
reload("riskFrequencyGrid");
});

initTable("riskFrequencyGrid");
});

// 風險發生偏好
dwrStuffRiskStat.queryRiskPreferences(o,function(data){
myChart("riskPreferences",data,function(event){
// 清空參數
clear();

// 拿到Id
var id = event.point.id;

$("#USER_ID").val(userId);

$("#RISK_TYPE").val(id);

// 加載表格
reload("riskPreferencesGrid");
});

initTable("riskPreferencesGrid");
});

// 風險整改情況
dwrStuffRiskStat.queryRiskRectify(o,function(data){

// 生成圖表
myChart("problemRectify",data,function(event){
// 清空參數
clear();

// 拿到項目ID
var projectId = event.point.id;

// 拿到整改情況datavalue
var typeId = event.point.series.options.seriesId;

$("#USER_ID").val(userId);

$("#REPORT_ID").val(projectId);

$("#REFORM_STATUS").val(typeId);

// 加載表格
reload("problemRectificationGrid");
});

initTable("problemRectificationGrid");
});

// 風險嚴重程度
dwrStuffRiskStat.queryRiskSeverity(o,function(data){
myChart("riskSeverity",data,function(event){
// 清空參數
clear();

// 拿到項目ID
var projectId = event.point.id;

// 拿到嚴重程度情況datavalue
var typeId = event.point.series.options.seriesId;

$("#USER_ID").val(userId);

$("#REPORT_ID").val(projectId);

$("#SEVERITY_LEVEL").val(typeId);

reload("riskSeverityGrid");
});

initTable("riskSeverityGrid");
});
}

// 點擊問題發生頻率柱子加載數據
function loadRisks(containerId)
{
// 爲表格加載數據
new AbmsGrid(containerId,{
colNames:['id','報告標題', '審計問題', '嚴重程度','類別'],
colModel:[
{name:'ID',key:true,width:55,hidden:true},
{name:'REPORT_TITLE',width:200},
{name:'RISK_CONTENT', width:100},
{name:'SEVERITY_LEVEL', width:50,align:'center'},
{name:'RISK_TYPE', width:100}
],
toolbar:false,
postParamNames:['USER_ID','REPORT_ID','RISK_TYPE','REFORM_STATUS','SEVERITY_LEVEL'],
_pageSql:'htsc.auditrisk.getRisks',
showPagerTool:true,
loadDataFlag:false,
caption: "風險審計問題"
});
}

// 重新加載
function reload(containerId)
{

// 重新刷新
// $("#"+containerId).trigger("reloadGrid");
queryGridData(containerId);
}

// 初始化表格
function initTable(ID)
{
// 先清空參數
clear();

// 重新加載
loadRisks(ID);
}

// 清空參數
function clear()
{
$("#USER_ID").val('');
$("#REPORT_ID").val('');
$("#RISK_TYPE").val('');
$("#REFORM_STATUS").val('');
$("#SEVERITY_LEVEL").val('');
};

</script>

****************************************************************************************************************
****************************************************封裝工具:myChart.js*****************************************
///////////////////////////////////////////////////組件的主題
/**
* Chart主題
* @author Torstein Honsi
*/
Highcharts.theme = {
// 默認顏色
colors:['#058DC7', '#50B432', '#ED561B', '#DDDF00', '#24CBE5', '#64E572', '#FF9655', '#FFF263', '#6AF9C4']
,chart:{
backgroundColor:{
linearGradient:{ x1:0, y1:0, x2:1, y2:1 }
,stops:[
[0, 'rgb(255, 255, 255)'],
[1, 'rgb(240, 240, 255)']
]
}
,borderWidth:2
,plotBackgroundColor:'rgba(255, 255, 255, .9)'
,plotShadow:true
,plotBorderWidth:1
}
,title:{
style:{
color:'#000'
,font:'bold 16px "Trebuchet MS", Verdana, sans-serif'
}
}
,subtitle:{
style:{
color:'#666666'
,font:'bold 12px "Trebuchet MS", Verdana, sans-serif'
}
}
,xAxis:{
gridLineWidth:1
,lineColor:'#000'
,tickColor:'#000'
,labels:{
style:{
color:'#000'
,font:'11px Trebuchet MS, Verdana, sans-serif'
}
}
,title:{
style:{
color:'#333'
,fontWeight:'bold'
,fontSize:'12px'
,fontFamily:'Trebuchet MS, Verdana, sans-serif'
}
}
}
,yAxis:{
minorTickInterval:'auto'
,lineColor:'#000'
,lineWidth:1
,tickWidth:1
,tickColor:'#000'
,labels:{
style:{
color:'#000'
,font:'11px Trebuchet MS, Verdana, sans-serif'
}
}
,title:{
style:{
color:'#333'
,fontWeight:'bold'
,fontSize:'12px'
,fontFamily:'Trebuchet MS, Verdana, sans-serif'
}
}
}
,legend:{
itemStyle:{
font:'9pt Trebuchet MS, Verdana, sans-serif'
,color:'black'
}
,itemHoverStyle:{
color:'#039'
}
,itemHiddenStyle:{
color:'gray'
}
}
,labels:{
style:{
color:'#99b'
}
}
,navigation:{
buttonOptions:{
theme:{
stroke:'#CCCCCC'
}
}
}
};

// 應用主題
var highchartsOptions =Highcharts.setOptions(Highcharts.theme);

// 顏色庫
var CHART_COLOR ={
// 深紅色
0:"#8B0000",
// 純紅色
1:"#FF0000",
// 橘紅色
2:"#EC561B",
// 橙色
3:"#FFA500",
// 純黃色
4:"#FFFF00",
// 淺黃色
5:"#FFC73C",
// 綠黃色
6:"#ADFF2F",
// 深綠色
7:"#006400",
// 純綠色
8:"#50B332",
// 淡綠色
9:"#90EE90",
// 深青色
10:"#008B8B",
// 青色
11:"#00FFFF",
// 淡青色
12:"#E1FFFF",
// 深藍色
13:"#00008B",
// 純藍色
14:"#58DC7",
// 淡天藍色
15:"#87CEFA",
// 淡藍色
16:"#86D6F1",
// 深紫羅蘭色
17:"#9400D3",
// 紫色
18:"#800080",
// 淡紫色
19:"#E7638B",
// 深灰色
20:"#A9A9A9",
// 灰色
21:"#808080",
// 淡灰色
22:"#CECECB",
// 純黑
23:"#000000",
// 米色
24:"#FBFCA4"
};

// 配置顏色
var COLOR_DICTIONARY={
//8種風險問題大類別
"0-01":2,
"0-02":5,
"0-03":8,
"0-04":19,
"0-05":16,
"0-06":22,
"0-07":24,
"0-08":8,

//3種問題嚴重程度
"1-1":16,
"1-2":5,
"1-3":2,

//4種問題整改類型
"6-1":15,
"6-2":5,
"6-3":8,
"6-4":2
};


////////////////////////////////////////////////////////////封裝的組件///////////////////////////////////
// 圖標X軸標題的傾斜度
var XAXIS_ROTATION = -30;

// 單個系列對象
function MyData(id,name,y){
this.id = id;
this.name=name;
this.y=y;
}

// 系列集合對象
function MySeries(type,seriesId,name,data){
this.type = type;
this.seriesId = seriesId;
this.name = name;
this.data = data;
}

// 封裝單個系列對象
function datas(columnType,categories,chartData)
{
var data = new Array();
if(chartData!=null &&chartData.length>0)
{
for(var i = 0;i<categories.length;i++){
// 生成series數據
var b = new MyData(categories[i].id,categories[i].name,chartData[i]);

// 如果是堆疊類型 數值爲0的,處理爲null,在圖標上不顯示
if(columnType==1&&b.y==0){ b.y= null; }

// 設置系列顏色
setColor(b,categories[i]['colorKey']);

data.push(b);
};
}

return data;
}

// 封裝系列集合對象
function getSeries(obj) {

var categories = obj['categories']

// 拿到系列數據
var seriesList = obj['seriesList'];

// 報表類型
var type = obj['chartType'];

// 針對堆疊類型
var columnType = obj['columnType'];

// 系列
var series = new Array();

// 如果系列數據不爲空
if(seriesList!=null&&seriesList.length>0)
{
var column = {};
var data ={};
var b ={};
for( var i= 0;i<seriesList.length;i++)
{
column = seriesList[i];
// 創建單個系列對象
data = datas(columnType,categories,column['chartData']);
if(data.length==0){
data=datas(columnType,categories,column['floatData']);
}

// 創建系列集合對象
b = new MySeries(type,column['id'],column['name'],data);

// 設置系列顏色
setColor(b,column['colorKey']);

series.push(b);
}
}

return series;
};

// 設置圖標顏色
function setColor(obj,colorKey)
{
if(colorKey!=null&&colorKey!=""){
obj.color = CHART_COLOR[COLOR_DICTIONARY[colorKey]%25];
}
}

// 封裝x軸顯示的數據
function xNames(obj)
{
var categories = obj['categories'];
var names = new Array();
for(var i=0;i<categories.length;i++)
{
names.push(categories[i].name);
}

return names;
}

// 封裝mychart對象
function myChart(containerId, obj, funcCode)
{
// 組建ID
this.containerId = containerId;
// 圖標類型
var chartType = obj['chartType'];
// 寬度
var width = obj['width'];
// 高度
var height = obj['height'];
// 標題
var title = obj['title'];
// 副標題
var subtitle = obj['subtitle'];
// x軸上的類型標題
var xCategories = xNames(obj);
// x軸標題
var xTitle = obj['xTitle'];
// y軸上的標題
var yTitle = obj['yTitle'];
// 提示的時候的單位
var unit = obj['unit'];
// 特殊的幾種類型圖標
var columnType = obj['columnType'];
// 點擊圖標的事件
var functionCode = funcCode;
// 系列集合
var series = getSeries(obj);

var chart;

/************************************
* 折線圖 *
************************************/
if (chartType == "line")
{
$(function() {
$(document).ready(function() {
chart = new Highcharts.Chart({
chart : {
renderTo : containerId,
width : width,
height : height,
type : chartType
},
// 到處功能的國際化
lang:{
exportButtonTitle: '導出',
printButtonTitle: '打印',
downloadJPEG:"下載JPEG 圖片",
downloadPDF: "下載PDF文檔",
downloadPNG: "下載PNG 圖片",
downloadSVG: "下載SVG 矢量圖"
},
// 版權信息
credits : {
enabled : false
},
// 標題
title : {
text : title
},
// 副標題
subtitle: {
text: subtitle
},
xAxis : {
categories : xCategories,
labels : {
//align : 'center',
formatter : function() {
return this.value;
},
rotation : XAXIS_ROTATION,
staggerLines : 1
},
tickInterval : 1,
title : {
text : xTitle
}
},
yAxis : {
labels : {
align : 'right',
formatter : function() {
return this.value;
}
},
tickInterval : 3,
title : {
text : yTitle
}
},
//是否有豎線
/* tooltip: {
crosshairs: true
},*/
plotOptions : {
series : {
cursor : 'pointer',
events : {
legendItemClick : false
},
pointWidth : 30
},
line : {
// 允許線性圖上的數據點進行點擊
allowPointSelect : true,
// 數據點的點擊事件
events : {
click : functionCode
},
// 當具體的數據點被點擊時的事件響應函數。如果不需要事件響應,可以刪除。
point : {
events : {
click : functionCode
}
},
// 是否在圖注中顯示。
showInLegend : true,
// 調整圖像順序關係
zIndex : 3
}
},
series : series
});

});
});
};

/************************************
* 縱向堆疊柱狀圖 *
************************************/
if (chartType=="column"&&columnType == 1)
{
$(function () {
$('#'+containerId).highcharts({
chart: {
width : width,
height : height,
type: chartType
},
credits : {
enabled : false
},
// 到處功能的國際化
lang:{
exportButtonTitle: '導出',
printButtonTitle: '打印',
downloadJPEG:"下載JPEG 圖片",
downloadPDF: "下載PDF文檔",
downloadPNG: "下載PNG 圖片",
downloadSVG: "下載SVG 矢量圖"
},
title: {
text: title
},
xAxis: {
categories: xCategories,
labels : {
// align : 'center',
formatter : function() {
return this.value;
},
rotation : XAXIS_ROTATION, // 傾斜度
staggerLines : 1,
style:{fontSize:10}
}
},
yAxis: {
min: 0,
title: {
text: yTitle
},
stackLabels: {
enabled: true,
style: {
fontWeight: 'bold',
color: (Highcharts.theme && Highcharts.theme.textColor) || 'gray'
}
}
},
legend: {
align: 'right',
x: -70,
verticalAlign: 'top',
y: 20,
floating: true,
backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColorSolid) || 'white',
borderColor: '#CCC',
borderWidth: 1,
shadow: false
},
tooltip: {
formatter: function() {
return '<b>'+ this.x +'</b><br/>'+
this.series.name +': '+ this.y + unit + '<br/>'+
'總數: '+ this.point.stackTotal + unit;
}
},
plotOptions: {
column: {
stacking: 'normal',
dataLabels: {
enabled: true,
color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white'
},
// 允許線性圖上的數據點進行點擊
allowPointSelect : true,

// 當具體的數據點被點擊時的事件響應函數。如果不需要事件響應,可以刪除。
point : {
events : {
click : functionCode
}
},
// 是否在圖注中顯示。
showInLegend : true,

// 調整圖像順序關係
zIndex : 3
}
},
series: series
});
});
}

/************************************
* 縱向柱形圖 *
************************************/
if (chartType == "column"&&columnType!= 1)
{
$(function() {
$(document).ready(function() {
chart = new Highcharts.Chart({
// Chart圖表區選項用於設置圖表區相關屬性
chart : {
renderTo : containerId,
width : width,
height : height,
type : chartType
},
// 到處功能的國際化
lang:{
exportButtonTitle: '導出',
printButtonTitle: '打印',
downloadJPEG:"下載JPEG 圖片",
downloadPDF: "下載PDF文檔",
downloadPNG: "下載PNG 圖片",
downloadSVG: "下載SVG 矢量圖"
},
credits : {
enabled : false
},
title : {
text : title
},
subtitle: {
text: subtitle
},
xAxis : {
categories : xCategories,
labels : {
// align : 'center', // X軸標題的位置
// 返回的格式
formatter : function() {
return this.value;
},
rotation : XAXIS_ROTATION, // 傾斜度
staggerLines : 1,
style:{fontSize:10}
},
tickInterval : 1,
title : {
text : xTitle
}
},
yAxis : {
labels : {
align : 'right',
formatter : function() {
return this.value;
}
},
tickInterval : 3,
title : {
text : yTitle
}
},
tooltip: {
formatter: function() {
return '<b>'+ this.x +'</b><br/>'+
this.series.name +': '+ this.y + unit;
}
},
plotOptions : {
series : {
cursor : 'pointer',
events : {
// 允許切換系列
legendItemClick : function(event){
return true;
}
},
pointWidth : 30
},
dataLabels : {
enabled : true
},
column : {
dataLabels:{
enabled:true //是否柱狀圖上顯示數值
},

// 允許線性圖上的數據點進行點擊
allowPointSelect : true,

// 當具體的數據點被點擊時的事件響應函數。如果不需要事件響應,可以刪除。
point : {
events : {
click : functionCode
}
},
// 是否在圖注中顯示。
showInLegend : true,
// 調整圖像順序關係
zIndex : 3
}
},
series : series
});
});
});
}

/************************************
* 曲線圖 *
************************************/
if (chartType == "spline")
{
$(function() {
$(document).ready(function() {
chart = new Highcharts.Chart({
chart : {
renderTo : containerId,
width : width,
height : height,
type : chartType
},
credits : {
enabled : false
},
title : {
text : title
},
subtitle: {
text: subtitle
},
xAxis : {
categories : xCategories,
labels : {
//align : 'center',
formatter : function() {
return this.value;
},
rotation : XAXIS_ROTATION,
staggerLines : 1
},
tickInterval : 1,
title : {
text : xTitle
}
},
yAxis : {
labels : {
align : 'right',
formatter : function() {
return this.value;
}
},
tickInterval : 3,
title : {
text : yTitle
}
},
plotOptions : {

series : {
cursor : 'pointer',
events : {
legendItemClick : false
},
pointWidth : 30
},
spline : {
// 允許線性圖上的數據點進行點擊
allowPointSelect : true,
// 數據點的點擊事件
events : {
click : functionCode
},
// 當具體的數據點被點擊時的事件響應函數。如果不需要事件響應,可以刪除。
point : {
events : {
click : functionCode
}
},
// 是否在圖注中顯示。
showInLegend : true,
// 調整圖像順序關係
zIndex : 3
}

},
series : series
});

});
});
}

/************************************
* 餅型圖 *
************************************/
if (chartType == "pie") {
$(function() {
$(document).ready(function() {
chart = new Highcharts.Chart({
chart : {
renderTo : containerId,
width : width,
height : height,
type : chartType
},
// 到導出功能的國際化
lang:{
exportButtonTitle: '導出',
printButtonTitle: '打印',
downloadJPEG:"下載JPEG 圖片",
downloadPDF: "下載PDF文檔",
downloadPNG: "下載PNG 圖片",
downloadSVG: "下載SVG 矢量圖"
},
credits : {
enabled : false
},
title : {
text : title
},
subtitle: {
text: subtitle
},
xAxis : {
categories : xCategories,
labels : {
// 標題顯示的位置
//align : 'center',
// X軸上顯示的標題格式
formatter : function() {
return this.value;
},
// 傾斜度
rotation : XAXIS_ROTATION,
staggerLines : 1,
style:{fontSize:10}
},
tickInterval : 1,
title : {
text : xTitle
}
},
yAxis : {
labels : {
align : 'right',
formatter : function() {
return this.value;
}
},
tickInterval : 3,
title : {
text : yTitle
}
},
tooltip: {
formatter: function() {
return '<b>'+ this.point.name +'</b>: '+ Highcharts.numberFormat(this.percentage, 1) +'% ('+
Highcharts.numberFormat(this.y, 0, ',') + unit +')';
},
useHTML:true
},
plotOptions : {
dataLabels: {
enabled: true,
color: '#000000',
connectorColor: '#000000',
formatter: function() {
return '<b>'+ this.point.name +'</b>: '+ this.percentage +' %';
}
},
pie:{
// 是否允許扇區點擊
allowPointSelect: true,
// 點擊後,滑開的距離
slicedOffset: 5,
// 餅圖的中心座標
// 餅圖的大小
// 數據標籤
dataLabels: {
format: '<b>{point.name}</b><br>{point.percentage:.1f} %',
// 是否允許標籤
enabled: true,
// 標籤與圖像元素之間的間距
distance: 10
},
// 數據點的點擊事件
events:{
click: functionCode
},
// 是否忽略隱藏的項
ignoreHiddenPoint: true,
// 當具體的數據點被點擊時的事件響應函數。如果不需要事件響應,可以刪除。
point:{
events:{
click: functionCode
}
},
// 是否在圖注中顯示。
showInLegend: true,
// 調整圖像順序關係
zIndex: 0
}
},
series : series
});

});
});
}

/************************************
* 正反堆疊條形圖 *
************************************/
if(chartType=="bar"&&columnType==2)
{
$(function () {
$('#'+containerId).highcharts({
chart: {
width : width,
height : height,
type : chartType
},
// 到導出功能的國際化
lang:{
exportButtonTitle: '導出',
printButtonTitle: '打印',
downloadJPEG:"下載JPEG 圖片",
downloadPDF: "下載PDF文檔",
downloadPNG: "下載PNG 圖片",
downloadSVG: "下載SVG 矢量圖"
},
title: {
text: title
},
subtitle: {
text: subtitle
},
xAxis: [{
categories: xCategories,
reversed: false
}, {
opposite: true,
reversed: false,
categories: xCategories,
linkedTo: 0
}],
yAxis: {
title: {
text: yTitle
},
labels: {
formatter: function(){
return Math.abs(this.value) + unit;
}
}
},

plotOptions: {
series: {
stacking: 'normal'
}
},

tooltip: {
formatter: function(){
return '<b>'+ this.point.category +'</b><br/>'+
yTitle +":"+ Math.abs(this.point.y)+ unit;
}
},

series: series
});
});
}

/************************************
* 橫向條形圖 *
************************************/
if (chartType == "bar"&&columnType!=2) {
$(function() {
$(document).ready(function() {

chart = new Highcharts.Chart({

chart : {
renderTo : containerId,
width : width,
height : height,
type : chartType
},
// 到處功能的國際化
lang:{
exportButtonTitle: '導出',
printButtonTitle: '打印',
downloadJPEG:"下載JPEG 圖片",
downloadPDF: "下載PDF文檔",
downloadPNG: "下載PNG 圖片",
downloadSVG: "下載SVG 矢量圖"
},
credits : {
enabled : false
},

title : {
text : title
},
subtitle: {
text: subtitle
},
xAxis : {
categories : xCategories,
labels : {
//align : 'center',
formatter : function() {
return this.value;
},
rotation :0,
staggerLines : 1
},
tickInterval : 1,
title : {
text : xTitle
}
},

yAxis : {
labels : {
align : 'right',
formatter : function() {
return this.value;
}
},
tickInterval : 3,
title : {
text : yTitle
}
},

plotOptions : {

series : {
cursor : 'pointer',
events : {
// 允許系列可以切換
legendItemClick : true
},
pointWidth : 30
},

bar : {
// 允許線性圖上的數據點進行點擊
allowPointSelect : true,
// 數據點的點擊事件
events : {
click : functionCode
},
// 當具體的數據點被點擊時的事件響應函數。如果不需要事件響應,可以刪除。
point : {
events : {
click : functionCode
}
},
// 是否在圖注中顯示。
showInLegend : true,
// 調整圖像順序關係
zIndex : 3
}

},
tooltip: {
formatter: function() {
return '<b>'+ this.x +'</b><br/>'+
this.series.name +': '+ this.y + unit;
}
},

series : series
});

});
});
}

/************************************
* 散播型 *
************************************/
if (chartType == "scatter") {
$(function() {
$(document).ready(function() {

chart = new Highcharts.Chart({

chart : {
renderTo : containerId,
width : width,
height : height,
type : chartType
},
// 到處功能的國際化
lang:{
exportButtonTitle: '導出',
printButtonTitle: '打印',
downloadJPEG:"下載JPEG 圖片",
downloadPDF: "下載PDF文檔",
downloadPNG: "下載PNG 圖片",
downloadSVG: "下載SVG 矢量圖"
},
credits : {
enabled : false
},

title : {
text : title
},
subtitle: {
text: subtitle
},

xAxis : {
categories : xCategories,
labels : {
//align : 'center',
formatter : function() {
return this.value;
},
rotation : XAXIS_ROTATION,
staggerLines : 1
},
tickInterval : 1,
title : {
text : xTitle
}
},

yAxis : {
labels : {
align : 'right',
formatter : function() {
return this.value;
}
},
tickInterval : 3,
title : {
text : yTitle
}
},

plotOptions : {

series : {
cursor : 'pointer',
events : {
legendItemClick : false
},
pointWidth : 30
},

scatter : {
// 允許線性圖上的數據點進行點擊
allowPointSelect : true,
// 數據點的點擊事件
events : {
click : functionCode
},
// 當具體的數據點被點擊時的事件響應函數。如果不需要事件響應,可以刪除。
point : {
events : {
click : functionCode
}
},
// 是否在圖注中顯示。
showInLegend : true,
// 調整圖像順序關係
zIndex : 3
}

},

series : series
});

});
});
}

/************************************
* 折線區域圖 *
************************************/
if (chartType == "area") {
$(function() {
$(document).ready(function() {

chart = new Highcharts.Chart({

chart : {
renderTo : containerId,
width : width,
height : height,
type : chartType
},
lang:{
exportButtonTitle: '導出',
printButtonTitle: '打印',
downloadJPEG:"下載JPEG 圖片",
downloadPDF: "下載PDF文檔",
downloadPNG: "下載PNG 圖片",
downloadSVG: "下載SVG 矢量圖"
},
credits : {
enabled : false
},

title : {
text : title
},
subtitle: {
text: subtitle
},

xAxis : {
categories : xCategories,
labels : {
//align : 'center',
formatter : function() {
return this.value;
},
rotation : XAXIS_ROTATION,
staggerLines : 1
},
tickInterval : 1,
title : {
text : xTitle
}
},

yAxis : {
labels : {
align : 'right',
formatter : function() {
return this.value;
}
},
tickInterval : 3,
title : {
text : yTitle
}
},

plotOptions : {

series : {
cursor : 'pointer',
events : {
legendItemClick : false
},
pointWidth : 30
},

area : {
// 允許線性圖上的數據點進行點擊
allowPointSelect : true,

// 當具體的數據點被點擊時的事件響應函數。如果不需要事件響應,可以刪除。
point : {
events : {
click : functionCode
}
},
// 是否在圖注中顯示。
showInLegend : true,
// 調整圖像順序關係
zIndex : 3
}
},
series : series
});

});
});
}

/************************************
* 曲線區域圖 *
************************************/
if (chartType == "areaspline") {
$(function() {
$(document).ready(function() {

chart = new Highcharts.Chart({

chart : {
renderTo : containerId,
width : width,
height : height,
type : chartType
},
credits : {
enabled : false
},

title : {
text : title
},
subtitle: {
text: subtitle
},

xAxis : {
categories : xCategories,
labels : {
//align : 'center',
formatter : function() {
return this.value;
},
rotation : XAXIS_ROTATION,
staggerLines : 1
},
tickInterval : 1,
title : {
text : xTitle
}
},

yAxis : {
labels : {
align : 'right',
formatter : function() {
return this.value;
}
},
tickInterval : 3,
title : {
text : yTitle
}
},

plotOptions : {

series : {
cursor : 'pointer',
events : {
legendItemClick : false
},
pointWidth : 30
},

areaspline : {
// 允許線性圖上的數據點進行點擊
allowPointSelect : true,
// 數據點的點擊事件
events : {
click : functionCode
},
// 當具體的數據點被點擊時的事件響應函數。如果不需要事件響應,可以刪除。
point : {
events : {
click : functionCode
}
},
// 是否在圖注中顯示。
showInLegend : true,
// 調整圖像順序關係
zIndex : 3
}

},

series : series
});
});
});
}
};

// 當數據爲空時的顯示
function noData_column(containerId){
$(function () {
$('#'+containerId).highcharts({
chart: {
type: 'column'
},
credits : {
enabled : false
},
title: {
text: '沒有符合條件的數據'
},
xAxis: {
categories: [
' ',' ',' ',' ',' ',' ',' ',
' ',' ',' ',' ',' ',' ',' ',
' ',' ',' ',' ',' ',' ',' ',
' ',' ',' ',' ',' ',' ',' '
]
},
yAxis: {
min: 0,
title: {
text: ''
}
},
plotOptions: {
column: {
pointPadding: 0.1,
borderWidth: 0
}
},
series: [{
name: 'no data',
data: [0, 0, 0,0, 0, 0,0,0, 0,0, 0, 0,0,0,0, 0, 0,0, 0, 0,0,0, 0,0, 0, 0,0,0]
}]
});
});
}

// 沒有數據時的餅圖
function noData_pie(containerId)
{
$(function () {
$('#'+containerId).highcharts({
chart: {
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false
},
credits : {
enabled : false
},
title: {
text: '沒有符合條件的數據'
},
tooltip: {
pointFormat: '{point.percentage:.1f}%</b>'
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer'
}
},
series: [{
type: 'pie',
name: 'no data',
data: [
{color:'#E5E5E5',name:'no data',y:100}
]
}]
});
});
}

************************************************************************************************
************************************************後臺數據封裝************************************
//////////////////////////DWR操作
package com.htsc.abms.auditrisk.dwr;

import com.htsc.abms.auditrisk.model.Model;
import com.htsc.abms.auditrisk.model.ChartType;
import com.htsc.abms.auditrisk.model.ChartsInfo;
import com.htsc.abms.auditrisk.service.AuditRiskService;
import org.springframework.beans.factory.annotation.Autowired;

/**
* Created with IntelliJ IDEA.
* User: 陳聖林
* Date: 14-5-21
* Time: 上午10:14
* 被稽查人員風險分析
*/
public class DwrStuffRiskStat {
/**
* 風險分析業務處理
*/
@Autowired
private AuditRiskService auditRiskService;

/**
* 查詢問題類型彙總
*
* @param model
* @return
*/
public ChartsInfo queryRiskTypeTotal(Model model) {
// 創建圖表
ChartsInfo data = new ChartsInfo("各類型問題發生總體情況", "", ChartType.CHART_PIE);
data.setUnit("個");
data.setWidth(500);

// 封裝業務數據
auditRiskService.setTypeTotalChart(data, model.getId());

return data;
}

/**
* 查選整改情況彙總
*
* @param model
* @return
*/
public ChartsInfo queryRiskRectifyTotal(Model model) {
// 創建圖表
ChartsInfo data = new ChartsInfo("問題整改總體情況", "", ChartType.CHART_PIE);
data.setUnit("個");
data.setWidth(500);

// 封裝業務數據
auditRiskService.setRectifyTotalChart(data, model.getId());

return data;
}

/**
* 查選嚴重等級彙總
*
* @param model
* @return
*/
public ChartsInfo queryRiskSeverityTotal(Model model) {
// 創建圖表
ChartsInfo data = new ChartsInfo("問題發生嚴重等級分佈", "", ChartType.CHART_PIE);
data.setUnit("個");
data.setWidth(500);

// 設置圖標數據
auditRiskService.setSeverityTotalChart(data, model.getId());
return data;
}

/**
* 查詢風險頻率
*
* @param model
* @return
*/
public ChartsInfo queryRiskFrequency(Model model) {
// 創建圖表
ChartsInfo data = new ChartsInfo("風險發生頻率", "問題數 (個)", ChartType.CHART_COLUMN);
data.setUnit("個");
// 設置圖標數據
auditRiskService.setRiskFrequencyChart(data, model.getId());

return data;
}

/**
* 查詢問題整改情況
*
* @param model
* @return
*/
public ChartsInfo queryRiskRectify(Model model) {
// 創建圖表
ChartsInfo data = new ChartsInfo("問題整改情況", "問題數 (個)", ChartType.CHART_COLUMN);
data.setUnit("個");
data.setColumnType(ChartsInfo.COLUMN_TYPE_CASCADE);

// 設置圖標數據
auditRiskService.setRiskRectifyChart(data, model.getId());

return data;
}

/**
* 查詢問題偏好
*
* @param model
* @return
*/
public ChartsInfo queryRiskPreferences(Model model) {
// 創建圖表
ChartsInfo data = new ChartsInfo("風險發生偏好", "問題數 (個)", ChartType.CHART_COLUMN);
data.setUnit("個");

// 設置圖標數據
auditRiskService.setRiskPreferencesChart(data, model.getId());

return data;
}

/**
* 查詢問題嚴重程度
*
* @param model
* @return
*/
public ChartsInfo queryRiskSeverity(Model model) {
// 創建圖表
ChartsInfo data = new ChartsInfo("風險發生程度詳情", "問題數 (個)", ChartType.CHART_COLUMN);
data.setUnit("個");

// 設置圖標數據
auditRiskService.setRiskSeverityChart(data, model.getId());

return data;
}

}

/////////////////////////////////////////Service類操作
package com.htsc.abms.auditrisk.service;

import com.htsc.abms.auditrisk.dao.AuditRiskDao;
import com.htsc.abms.auditrisk.model.*;
import com.htsc.abms.auditrisk.util.RiskStatServiceUtil;
import com.lhzq.ibms.commons.model.DataDictionaryDetail;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

/**
* Created with IntelliJ IDEA.
* User: 陳聖林
* Date: 14-5-22
* Time: 下午11:57
* 被稽查人員審計風險分析
*/
@Service
@Transactional
public class AuditRiskService {
/**
* 風險審計持久層
*/
@Autowired
private AuditRiskDao auditRiskDao;

/**
* 輔助工具
*/
@Autowired
private RiskStatServiceUtil riskStat;

/**
* 設置類型彙總視圖數據
*
* @param chart 圖表
* @param userId 用戶ID
*/
public void setTypeTotalChart(ChartsInfo chart, String userId) {
// 查詢數據
List<Model> data = auditRiskDao.getRiskTypeTotal(newParam(userId));

Series ss = new Series("001", "所佔比例");
ss.setChartData(riskStat.setCategories(chart, data));
chart.getSeriesList().add(ss);
}

/**
* 設置整改彙總數據
*
* @param chart 圖表
* @param userId 用戶ID
*/
public void setRectifyTotalChart(ChartsInfo chart, String userId) {
List<Model> data = auditRiskDao.getRiskRectifyTotal(newParam(userId));

Series ss = new Series("001", "所佔比例");
ss.setChartData(riskStat.setCategories(chart, data));
chart.getSeriesList().add(ss);
}

/**
* 設置嚴重程度彙總數據
*
* @param chart 圖表
* @param userId 用戶ID
*/
public void setSeverityTotalChart(ChartsInfo chart, String userId) {
List<Model> data = auditRiskDao.getRiskSeverityTotal(newParam(userId));

Series ss = new Series("001", "所佔比例");
ss.setChartData(riskStat.setCategories(chart, data));
chart.getSeriesList().add(ss);
}

/**
* 設置項目發生頻率數據
*
* @param chart 圖表
* @param userId 用戶ID
*/
public void setRiskFrequencyChart(ChartsInfo chart, String userId) {
List<Model> data = auditRiskDao.getRiskFrequency(newParam(userId));

Series ss = new Series("001", "風險發生頻率");
ss.setChartData(riskStat.setCategories(chart, data));
chart.getSeriesList().add(ss);
}

/**
* 設置風險發生偏好統計數據
*
* @param chart 圖標
* @param userId 用戶ID
*/
public void setRiskPreferencesChart(ChartsInfo chart,String userId) {
List<Model> data = auditRiskDao.getRiskPreferences(newParam(userId));
Series ss = new Series("001", "風險發生偏好");
ss.setChartData(riskStat.setCategories(chart, data));
chart.getSeriesList().add(ss);
}

/**
* 設置風險等級統計數據
*
* @param chart 圖表
* @param userId 用戶ID
*/
public void setRiskRectifyChart(ChartsInfo chart,String userId) {
List<Model> data = auditRiskDao.getRiskRectification(newParam(userId));

// 查詢整改類型
List<Model> rectTypes = auditRiskDao.getTypeDictionary(DataDictionaryDetail.DATA_TYPE_RECTIFY);
riskStat.setChartData(chart, rectTypes, data);
}

/**
* 設置嚴重程度統計數據
*
* @param chart 圖表
* @param userId 用戶ID
*/
public void setRiskSeverityChart(ChartsInfo chart, String userId) {
List<Model> data = auditRiskDao.getRiskSeverity(newParam(userId));

// 查詢整改類型
List<Model> rectTypes = auditRiskDao.getTypeDictionary(DataDictionaryDetail.DATA_TYPE_SEVERITY);
riskStat.setChartData(chart, rectTypes, data);
}

/**
* 封裝參數
*
* @param userId
* @return
*/
private Map newParam(String userId) {
Map map = new HashMap();
map.put("USER_ID", userId);

return map;
}

}

////////////////////////////////////////////////////Dao的操作類
package com.htsc.abms.auditrisk.dao;

import com.htsc.abms.auditrisk.model.Model;
import com.htsc.abms.auditrisk.model.QueryCondition;
import com.lhzq.ibms.commons.dao.EntityDao;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* Created with IntelliJ IDEA.
* User: 陳聖林
* Date: 14-5-22
* Time: 下午7:02
* 風險發生頻率統統計持久層
*/
@Repository
public class AuditRiskDao extends EntityDao {
/**
* 設置SQL空間
*/
public AuditRiskDao() {
this.setNamespace("htsc.auditrisk");
}

/**
* 根據用戶查詢風險類型彙總
*
* @param param
* @return
*/
public List<Model> getRiskTypeTotal(Map param)
{
return queryForList("getRiskTypeTotal", param, Model.class);
}

/**
* 根據用戶查詢風險整改彙總
*
* @param param
* @return
*/
public List<Model> getRiskRectifyTotal(Map param)
{
return queryForList("getRiskRectifyTotal", param, Model.class);
}

/**
* 根據用戶查詢風險嚴重等級彙總
*
* @param param
* @return
*/
public List<Model> getRiskSeverityTotal(Map param)
{
return queryForList("getRiskSeverityTotal", param, Model.class);
}

/**
* 根據用戶查詢風險頻率
*
* @param param
* @return
*/
public List<Model> getRiskFrequency(Map param)
{
return queryForList("getRiskFrequency", param, Model.class);
}

/**
* 根據用戶查詢風險偏好
*
* @param param
* @return
*/
public List<Model> getRiskPreferences(Map param)
{
return queryForList("getRiskPreferences", param, Model.class);
}


/**
* 根據用戶查詢風險整改情況
*
* @param param
* @return
*/
public List<Model> getRiskRectification(Map param)
{
return queryForList("getRiskRectification", param, Model.class);
}

/**
* 根據項目查詢風險嚴重程度
*
* @param param
* @return
*/
public List<Model> getRiskSeverity(Map param)
{
return queryForList("getRiskSeverity", param, Model.class);
}

/**
* 根據類型查詢數據詞典類型
*
* @param dataType
* @return
*/
public List<Model> getTypeDictionary(int dataType) {
Map map = new HashMap();
map.put("DATATYPE", dataType);

return queryForList("getTypeDictionary", map, Model.class);
}


/**
* 查詢所有的單位數
* @param map
* @return
*/
public Integer getReportCounts(Map map)
{
return this.queryForInt("getReportCounts",map);
}

/**
* 查詢風險類型
* @param map
* @return
*/
public List<Model> getAuditRiskType(Map map)
{
return this.queryForList("getAuditRiskType",map,Model.class);
}

/**
* 根據
* @param map
* @return
*/
public List<Model> getAuditRiskTypeByCode(Map map)
{
return this.queryForList("getAuditRiskTypeByCode",map,Model.class);
}

/**
* 查詢各類的損失金額
* @param map
* @return
*/
public List<Model> getLossSituation(Map map)
{
return this.queryForList("getLossSituation",map,Model.class);
}

// 機構總數
public List<Model> getTotalOrgCount(){
Map map = new HashMap();
return this.queryForList("getTotalOrgCount",map,Model.class);
}

// 風險問題覆蓋率
public List<Model> getCoverageRate(Map map){
return this.queryForList("getCoverageRate",map,Model.class);
}


// 風險問題發生地域性
public List<Model> getHappenArea(Map map){
return this.queryForList("getHappenArea",map,Model.class);
}

// 風險問題整改情況-所屬區域
public List<Model> queryRectifyByArea(Map map){
return this.queryForList("getRectifyByArea",map,Model.class);
}

public List<Model> getMonthSeverity(Map map)
{
return this.queryForList("getMonthSeverity",map,Model.class);
}

// 風險問題整改情況-風險大類
public List<Model> queryRectifyByRiskType(Map map){
return this.queryForList("getRectifyByRiskType",map,Model.class);
}

// 風險問題整改情況-嚴重程度
public List<Model> queryRectifyBySeverityLevel(Map map){
return this.queryForList("getRectifyBySeverityLevel",map,Model.class);
}

}

////////////////////////////////////////HighChart的X軸上的單個系列數據封裝
package com.htsc.abms.auditrisk.model;

/**
* Created with IntelliJ IDEA.
* User: 陳聖林
* Date: 14-5-24
* Time: 下午4:05
* Chart標題分類
*/
public class Category
{
protected String id;

protected String name;

protected String colorKey;

public Category(){};

public Category(Model model) {
this.id = model.getId();
this.name = model.getName();
this.colorKey =model.getColorKey();
}

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getColorKey() {
return colorKey;
}

public void setColorKey(String colorKey) {
this.colorKey = colorKey;
}
}

//////////////////////////////////////////////////////HightChart基本信息封裝
package com.htsc.abms.auditrisk.model;

import org.omg.CORBA.PUBLIC_MEMBER;

import java.util.ArrayList;
import java.util.List;

/**
* Created with IntelliJ IDEA.
* User: 陳聖林
* Date: 14-5-21
* Time: 上午9:50
* 報表對象封裝
*/
public class ChartsInfo
{
/**
* 默認的高度
*/
public static final int DEFAULT_HEIGHT = 400;

/**
* 默認的寬度
*/
public static final int DEFAULT_WIDTH = 1000;

/**
* 默認的單位
*/
public static final String DEFAULT_UNIT = "個";

/**
* 堆疊柱狀圖
*/
public static final int COLUMN_TYPE_CASCADE = 1;

/**
* 正反對比圖
*/
public static final int COLUMN_TYPE_OPPOSITE_CASCADE = 2;

/**
* 報表在頁面上顯示的寬度
*/
private int width;

/**
* 報表在頁面上顯示的高度
*/
private int height;

/**
* 報表名稱
*/
private String title;

/**
* 報表名稱
*/
private String subtitle;

/**
* 橫座標名稱
*/
private String xTitle;

/**
* 縱座標名稱
*/
private String yTitle;

/**
* 提示單位
*/
private String unit;

/**
* 報表類型(分爲十種,在ChartType公共常量類定義)
*/
private String chartType;

/**
* 特殊類型 1.表示堆疊柱狀圖 2.正反對比圖 0.其他
*/
private int columnType;

/**
* 橫座標所需列
*/
private List<Category> categories= new ArrayList<Category>();

/**
* 系列數據
*/
private List<Series> seriesList = new ArrayList<Series>();

public ChartsInfo(){}

public ChartsInfo(String title, String yTitle, String chartType)
{
this.title = title;
this.yTitle = yTitle;
this.chartType = chartType;
this.height = DEFAULT_HEIGHT;
this.width = DEFAULT_WIDTH;
this.unit = DEFAULT_UNIT;
}

public List<Category> getCategories() {
return categories;
}

public void setCategories(List<Category> categories) {
this.categories = categories;
}

public int getWidth() {
return width;
}

public void setWidth(int width) {
this.width = width;
}

public int getHeight() {
return height;
}

public void setHeight(int height) {
this.height = height;
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

public String getSubtitle() {
return subtitle;
}

public void setSubtitle(String subtitle) {
this.subtitle = subtitle;
}

public String getxTitle() {
return xTitle;
}

public void setxTitle(String xTitle) {
this.xTitle = xTitle;
}

public String getyTitle() {
return yTitle;
}

public void setyTitle(String yTitle) {
this.yTitle = yTitle;
}

public String getChartType() {
return chartType;
}

public void setChartType(String chartType) {
this.chartType = chartType;
}

public List<Series> getSeriesList() {
return seriesList;
}

public void setSeriesList(List<Series> seriesList) {
this.seriesList = seriesList;
}

public int getColumnType() {
return columnType;
}

public void setColumnType(int columnType) {
this.columnType = columnType;
}

public String getUnit() {
return unit;
}

public void setUnit(String unit) {
this.unit = unit;
}
}


//////////////////////////////////////////////HighChart的X軸上系列集數據分裝
package com.htsc.abms.auditrisk.model;

/**
* Created with IntelliJ IDEA.
* User: 陳聖林
* Date: 14-5-21
* Time: 下午2:09
* 系列
*/
public class Series extends Category
{
/**
* 報表(縱座標)值
*/
private Integer[] chartData;

private Float[] floatData;

public Series(){}

public Series(String id,String name)
{
this.id =id;
this.name = name;
}

public Integer[] getChartData() {
return chartData;
}

public void setChartData(Integer[] chartData) {
this.chartData = chartData;
}

public Float[] getFloatData() {
return floatData;
}

public void setFloatData(Float[] floatData) {
this.floatData = floatData;
}
}


//////////////////////////////////////////////////對應數據庫數據Model
package com.htsc.abms.auditrisk.model;

/**
* Created with IntelliJ IDEA.
* User: 陳聖林
* Date: 14-5-22
* Time: 下午7:04
* 問題發生頻率
*/
public class Model extends Category
{
/**
* 值
*/
private Integer value;

/*
* 多維度
*/
private String typeId;

/**
* 類型ID
*/
private String typeName;

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Model)) return false;

Model model = (Model) o;

if (!this.id.equals(model.id)) return false;
if (!this.name.equals(model.name)) return false;
if (this.value!=model.value) return false;
if (!this.colorKey.equals(model.colorKey)) return false;

return true;
}

public Integer getValue() {
return value;
}

public void setValue(Integer value) {
this.value = value;
}

public String getTypeName() {
return typeName;
}

public void setTypeName(String typeName) {
this.typeName = typeName;
}

public String getTypeId() {
return typeId;
}

public void setTypeId(String typeId) {
this.typeId = typeId;
}
}


//////////////////////////////////////////////////幫助類util
package com.htsc.abms.auditrisk.util;

import com.htsc.abms.auditrisk.model.*;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
* Created with IntelliJ IDEA.
* User: 陳聖林
* Date: 14-6-6
* Time: 上午10:46
* 風險審計統計Service的公共方法
*/
@Service
public class RiskStatServiceUtil
{
/**
* 設置categories的值
* @param chart
* @param data
* @return
*/
public Integer[] setCategories(ChartsInfo chart,List<Model> data)
{
Integer [] values = new Integer[data.size()];

int i = 0;
for(Model model : data)
{
chart.getCategories().add(new Category(model));
values[i++] = model.getValue();
}

return values;
}

/**
* 設置多系列的數據
* @param chart
* @param rectTypes
* @param data
*/
public void setChartData(ChartsInfo chart,List<Model> rectTypes,List<Model> data)
{
// 過濾報告
Set<String> filter = new HashSet<String>();

int rectCount = rectTypes.size();
int reportCount = data.size()/rectTypes.size();

// 定義二維數組存放series的數據
Integer[][] chartArray = new Integer[rectCount][reportCount];

int x = 0;
int y = 0;
Model temp = null;
List<Model> reports = new ArrayList<Model>();
for(int i=0;i<data.size();i++)
{
temp = data.get(i);
chartArray[y][x] = temp.getValue();
x++;
if(x==reportCount){
x=0;
y++;
}

if(!filter.contains(temp.getId()))
{
filter.add(temp.getId());
reports.add(temp);
}
}

// 設置series
Series series = null;
for(int i=0;i<rectCount;i++)
{
temp = rectTypes.get(i);
series = new Series();
series.setId(temp.getId());
series.setName(temp.getName());
series.setColorKey(temp.getColorKey());
series.setChartData(chartArray[i]);
chart.getSeriesList().add(series);
}

// 設置categories
for(Model m: reports)
{
chart.getCategories().add(new Category(m));
}
}
}


////////////////////////////////////////////////////HighChart類型常量封裝
package com.htsc.abms.auditrisk.model;

/**
* Created with IntelliJ IDEA.
* User: 陳聖林
* Date: 14-5-21
* Time: 上午9:52
* Chart類型常量
*/
public final class ChartType
{
// 折線形
public static final String CHART_LINE = "line";

// 曲線圖
public static final String CHART_SPLINE = "spline";

//縱向單列柱狀圖
public static final String CHART_COLUMN = "column";

//橫向條形圖
public static final String CHART_BAR = "bar";

//餅形圖
public static final String CHART_PIE = "pie";

//散播點圖
public static final String CHART_SCATTER = "scatter";

//區域折線圖
public static final String CHART_AREA = "area";

//區域曲線圖
public static final String CHART_AREA_SPLINE = "areaspline";
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章