function getURL() { var url = window.location.href var arr = url.split("?") var ar = arr[1] return ar } //窗口大小变化时延时刷新图表大小 $(window).resize(function () { var width = $(window).width() ;(width -= 202), $("#chartdiv").width(width) }) function getQueryString(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)") var r = window.location.search.substr(1).match(reg) if (r != null) return unescape(r[2]) return null } // 加载 $(document).ready(function () { cid = getQueryString("cid") showDateSelect() typeSelect() showMonitorTree() showBuildTree() }) function showDateSelect() { var date = new Date() var month = date.getMonth() + 1 var year = date.getFullYear() var monthData = [] for (var i = 1; i < 13; i++) { var json = {} json["text"] = i if (i < 10) { json["value"] = "0" + i } else { json["value"] = "" + i } if (i == month) { json["selected"] = "true" } monthData.push(json) } var yearData = [] for (var i = 0; i < 10; i++) { var json = {} json["text"] = year - i json["value"] = year - i if (i == 0) { json["selected"] = "true" } yearData.push(json) } $("#year").combobox({ data: yearData, valueField: "value", textField: "text", width: 80, panelHeight: 210, }) $("#month").combobox({ data: monthData, valueField: "value", textField: "text", width: 60, panelHeight: 250, }) } var monitorId = undefined, type = 1, monitorName // 展示左侧树 function showMonitorTree() { ajax({ url: "/web/getMonitorTree/tree.json", type: "POST", data: { cid: cid, }, dataType: "JSON", success: function (data) { $("#monitorInfo").tree({ // url : '/web/getMonitorTree/tree.json?cid=1', onClick: function (node) { /* * monitorId = node.id; monitorName = node.text; * init_data(); */ }, data: data["data"], onLoadSuccess: function (node, data) { var firstNode = $("#monitorInfo").tree("getChildren", $("#monitorInfo").tree("getRoot").target)[0] if (firstNode) { $("#monitorInfo").tree("select", firstNode.target) query() } }, }) }, error: function (XMLHttpRequest, textStatus, errorThrown) { if (XMLHttpRequest.status == 200) { layer.msg(XMLHttpRequest.responseText, { icon: 2, }) } else { layer.msg("服务存在异常,请稍后再试!", { icon: 2, }) } }, }) } function showBuildTree() { ajax({ url: "/web/buildingmornitor/getBuildingMonitorTree.json", type: "POST", data: { cid: cid, }, dataType: "JSON", success: function (data) { $("#buildTree").tree({ onClick: function (node) { /* * monitorId = node.id; monitorName = node.text; * init_data(); */ }, data: data["data"], onLoadSuccess: function (node, data) { var firstNode = $("#buildTree").tree("getChildren", $("#buildTree").tree("getRoot").target)[0] if (firstNode) { $("#buildTree").tree("select", firstNode.target) } }, }) }, error: function (XMLHttpRequest, textStatus, errorThrown) { if (XMLHttpRequest.status == 200) { layer.msg(XMLHttpRequest.responseText, { icon: 2, }) } else { layer.msg("服务存在异常,请稍后再试!", { icon: 2, }) } }, }) } function typeSelect() { $("#type").combobox({ onChange: function (newVal, oldVal) { type = newVal if (newVal == 1) { $("#monthSpan").show() } else { $("#monthSpan").hide() } }, }) } function exportExcel() { var selectName = $("#tt").tabs("getSelected").panel("options")["title"] var date if (type == 1) date = $("#year").combobox("getValue") + $("#month").combobox("getValue") else date = $("#year").combobox("getValue") if (selectName == "监测点") { var node = $("#monitorInfo").tree("getSelected") if (!node || node["attribute"]["type"] == "company") { return } var terminalId = node["attribute"]["terminalId"] exportMonitorData(date, terminalId, node["text"]) } else if (selectName == "企业区域") { var node = $("#buildTree").tree("getSelected") if (!node || node["attribute"]["type"] == "company") { return } if (node["attribute"]["type"] == "monitor") { var terminalId = node["attribute"]["terminalId"] exportMonitorData(date, terminalId, node["text"]) } else if (node["attribute"]["type"] == "building") { var buildingId = node["id"] exportBuildingData(date, buildingId, node["text"]) } } } function exportBuildingData(date, buildingId, name) { var auth_aid = getQueryString("auth_aid") var auth_mid = getQueryString("auth_mid") name = name.replace("#", "-") window.open("/web/assess/shiftsAssess/exportExcel.json?time=" + date + "&buildingId=" + buildingId + "&name=" + name + "&type=2&" + getURL()) } function exportMonitorData(date, terminalId, name) { var auth_aid = getQueryString("auth_aid") var auth_mid = getQueryString("auth_mid") name = name.replace("#", "-") window.open("/web/assess/shiftsAssess/exportExcel.json?time=" + date + "&terminalId=" + terminalId + "&name=" + name + "&type=1&" + getURL()) } function query() { var selectName = $("#tt").tabs("getSelected").panel("options")["title"] var date if (type == 1) date = $("#year").combobox("getValue") + $("#month").combobox("getValue") else date = $("#year").combobox("getValue") if (selectName == "监测点") { var node = $("#monitorInfo").tree("getSelected") if (!node || node["attribute"]["type"] == "company") { return } var terminalId = node["attribute"]["terminalId"] getMonitorData(date, terminalId) } else if (selectName == "企业区域") { var node = $("#buildTree").tree("getSelected") if (!node || node["attribute"]["type"] == "company") { return } if (node["attribute"]["type"] == "monitor") { var terminalId = node["attribute"]["terminalId"] getMonitorData(date, terminalId) } else if (node["attribute"]["type"] == "building") { var buildingId = node["id"] getBuildingData(date, buildingId) } } } function getMonitorData(date, terminalId) { ajax({ url: "/web/assess/shiftsAssess/getData.json", type: "POST", beforeSend: function (XHR) { $("#center").mask("数据加载中...") }, data: { terminalId: terminalId, time: date, type: 1, }, dataType: "JSON", success: function (data) { $("#center").unmask() if (data["status"] == 1) { init_table(data["data"]) if (type == 1) { showMonthChart(data["data"]) } else { showYearChart(data["data"]) } } }, }) } function getBuildingData(date, buildingId) { ajax({ url: "/web/assess/shiftsAssess/getData.json", type: "POST", beforeSend: function (XHR) { $("#center").mask("数据加载中...") }, data: { buildingId: buildingId, time: date, type: 2, }, dataType: "JSON", success: function (data) { $("#center").unmask() if (data["status"] == 1) { init_table(data["data"]) if (type == 1) { showMonthChart(data["data"]) } else { showYearChart(data["data"]) } } }, }) } function init_table(data) { var heightval = $("body").height() - 365 $("#dg").datagrid({ border: false, singleSelect: true, height: heightval, frozenColumns: [ [ { field: "date", title: "日期", width: 150, align: "center", formatter: function (value) { if (value.length == 6) { value = value.substring(0, 4) + "-" + value.substring(4, 6) } else { value = value.substring(0, 4) + "-" + value.substring(4, 6) + "-" + value.substring(6) } return value }, }, { field: "total", title: "总和", width: 150, align: "right", }, ], ], columns: [ [ { field: "tpe1", title: "早班", width: 150, align: "right", }, { field: "tpe2", title: "中班", width: 150, align: "right", }, { field: "tpe3", title: "晚班", width: 150, align: "right", }, { field: "tpe4", title: "其它", width: 150, align: "right", }, ], ], data: data, }) } var options = { global: { useUTC: false, }, colors: ["#24CBE5", "#64E572", "#FF9655", "#FFF263", "#6AF9C4"], legend: { align: "center", verticalAlign: "bottom", itemStyle: { fontWeight: "bold", fontSize: "13px", }, }, credits: { enabled: false, }, } // Apply the theme var highchartsOptions = Highcharts.setOptions(options) function getSeries(data) { if (data && data.length) { var serie1 = {}, serie2 = {}, serie3 = {}, serie4 = {} var series = [serie1, serie2, serie3, serie4] serie1["name"] = "早班" serie2["name"] = "中班" serie3["name"] = "晚班" serie4["name"] = "其他" var data1 = [], data2 = [], data3 = [], data4 = [] serie1["data"] = data1 serie2["data"] = data2 serie3["data"] = data3 serie4["data"] = data4 $.each(data, function (i, n) { var json1 = {}, json2 = {}, json3 = {}, json4 = {} json1["x"] = n["timestamp"] json2["x"] = n["timestamp"] json3["x"] = n["timestamp"] json4["x"] = n["timestamp"] if (n["tpe1"] != 0) { json1["y"] = n["tpe1"] } else { json1["y"] = null } if (n["tpe2"] != 0) { json2["y"] = n["tpe2"] } else { json2["y"] = null } if (n["tpe3"] != 0) { json3["y"] = n["tpe3"] } else { json3["y"] = null } if (n["tpe4"] != 0) { json4["y"] = n["tpe4"] } else { json4["y"] = null } /* * json2['y'] = n['tpe2']; json3['y'] = n['tpe3']; json4['y'] = * n['tpe4']; */ data1.push(json1) data2.push(json2) data3.push(json3) data4.push(json4) }) return series } } function showYearChart(data) { var series = getSeries(data) $("#chartdiv").highcharts({ chart: { type: "column", }, title: { text: getTitle(), }, xAxis: { type: "datetime", tickInterval: 24 * 3600 * 1000, gridLineWidth: 1, // 默认是0,即在图上没有纵轴间隔线 // 自定义x刻度上显示的时间格式,根据间隔大小,以下面预设的小时/分钟/日的格式来显示 dateTimeLabelFormats: { // hour:"%m-%e %H:%M", // day : "%e" month: "%m", }, }, yAxis: { title: { text: "电量(KW.h)", }, lineWidth: 1, stackLabels: { enabled: false, style: { fontWeight: "bold", color: (Highcharts.theme && Highcharts.theme.textColor) || "gray", }, }, }, legend: { align: "center", verticalAlign: "bottom", itemStyle: { fontWeight: "bold", fontSize: "13px", }, // floating : true, backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColorSolid) || "white", borderColor: "#CCC", borderWidth: 1, shadow: false, }, tooltip: { pointFormat: '