var layer; var chartLine; $(function() { layui.use([ 'layer', 'laydate', 'form' ], function() { var form = layui.form; // 只有执行了这一步,部分表单元素才会自动修饰成功 layer = layui.layer; layDate = layui.laydate; form.render(); // 日期 layDate.render({ elem : '#start' }); // 日期 layDate.render({ elem : '#end' }); }); // 根据页面自动计算余下款低-选择框的高度 var bodyHeight = window.innerHeight; var headerHeight = $("#header-condition").height(); $("#container").css("height", bodyHeight - headerHeight - 40); // 初始化显示走势图 chartLine = initChartLine(); }); // 执行查询 function query() { var data = {}; var t = $('#form-query').serializeArray(); $.each(t, function() { data[this.name] = this.value; }); var index = layer.load(0); $.ajax({ type : "POST", url : "../../basic/grain/query-line-data", dataType : "json", contentType : "application/json;charset=UTF-8", data : JSON.stringify(data), success : function(result) { layer.close(index); if (result.code != "0000") { layer.msg(result.msg); return; } renderLine(result.data); }, error : function(result) { layer.msg("获取数据失败,请重新尝试!"); } }); }; // 重新渲染走势图 function renderLine(lineData) { chartLine.option.legend.data = lineData.legendData; chartLine.option.xAxis[0].data = lineData.xaxisData; chartLine.option.series = lineData.series; chartLine.chart.setOption(chartLine.option, true); }; function initChartLine() { var option = { title : { text : '粮情三温走势分析(单位:℃)', show : true }, tooltip : { trigger : 'axis', axisPointer : { type : 'cross', label : { backgroundColor : '#6a7985' } } }, legend : { data : [ '仓温', '外温', '平均粮温', '最高粮温', '最低粮温' ], bottom : '20', top : 'bottom' }, toolbox : { feature : { saveAsImage : {} } }, grid : { left : '3%', right : '3%', bottom : '4%', containLabel : true }, xAxis : [ { data : [ '01:00', '02:00', '03:00', '04:00', '05:00', '06:00', '07:00', '08:00', '09:00', '10:00', '11:00', '12:00' ] } ], yAxis : [ { type : 'value' } ], series : [ { name : '仓温', type : 'line', 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 ] }, { name : '外温', type : 'line', 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 ] }, { name : '平均粮温', type : 'line', 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 ] }, { name : '最高粮温', type : 'line', 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 ] }, { name : '最低粮温', type : 'line', data : [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] } ] }; var myChart = echarts.init(document.getElementById("container"), "light"); myChart.setOption(option, true); return { "chart" : myChart, "option" : option }; };