$(function() { $("div.data").hide(); $("#graphViewBtn").on('click',showGraphView); $("#dataViewBtn").on('click',showDataView); $('a[data-toggle="tab"]').on('shown.bs.tab',changeLeftTitle); showSerialChart("graphOne"); showPieChart("graphTwo"); init(); }); function init() { var today=new Date(), todayDate=new Date(today.getFullYear(),today.getMonth(),today.getDate()); //设置时间格式 $("#startDate,#endDate").datepicker({ language: 'zh-CN', autoclose: true, endDate:"Today", todayBtn:"linked", format:"yyyy-mm-dd" }); $("#startDate").datepicker('update',todayDate); $("#endDate").datepicker('update',todayDate); //select $(".select").selectpicker(); //高度 $(".left-region").height($(".right-region").height()); } /** * 显示图形视图 */ function showGraphView(event) { $("div.data").hide(); $("div.graph").show(); showSerialChart("graphOne"); showPieChart("graphTwo"); } /** * 显示表格视图 */ function showDataView(event) { $("div.data").show(); $("div.graph").hide(); showSerialData(); showPieData(); } function showSerialChart(chartDiv) { var chart = AmCharts.makeChart(chartDiv, { "type": "serial", "dataProvider": DataSet.serialData, "valueAxes": [ { "gridColor": "black", "gridAlpha": 0.4, // "axisAlpha": 0, "dashLength": 8, "position": "left", "autoGridCount":false, "gridCount":3, "title":"总能耗(kgce)" } ], "gridAboveGraphs": true, "startDuration": 0, //second "graphs": [ { "balloonText": "[[category]]: [[value]]", "fillAlphas": 0.8, "fillColors":'#FF62FF', "lineAlpha": 0.2, "columnWidth":0.6, "type": "column", "valueField": "value" } ], "chartCursor": { "categoryBalloonEnabled": false, "cursorAlpha": 0, "zoomable": false }, "categoryField": "time", "categoryAxis": { "gridPosition": "start", "gridAlpha": 0.4, "dashLength":8, "dateFormats":[{period:'hh',format:'JJ:NN'}], "tickPosition": "start", "autoGridCount":false, "gridCount":6, // "tickLength": 20 // title:"总耗能", // "position":"top" }, } ); } function showPieChart(chartDiv) { var chart = AmCharts.makeChart(chartDiv, { "type": "pie", "startDuration": 0, "addClassNames": true, "legend":{ "position":"right", "autoMargins":true, "valueText":"[[value]]kgce",//gkq:debug }, "minRadius":80, "innerRadius": "40%", "radius":"40%", //gkq:debug "pullOutRadius":0, "dataProvider": DataSet.pieData, "valueField": "value", "titleField": "item", "labelRadius":-30, //gkq:debug "colors":['#5AB6DF','#FFC64B','#5ADF75','#FC8675','#6A8ABE','#FFA24B','#916DDC','#B5EB5F','#EC6E96','#EEF658'], "outlineThickness":2, "outlineAlpha":0.8, "labelText":"[[percents]]%", "labelsEnabled":true, "percentPrecision":0 }); } function showSerialData() { var html=""; $.each(DataSet.serialData, function(index, entity) { html+="