lxw
2020-07-11 9db52f2f2dd3665fe9da1ae5657e0167c3a34d40
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<!DOCTYPE html>
<html>
  <head>
    <title>温度折线图</title>
    
    <meta name="keywords" content="keyword1,keyword2,keyword3">
    <meta name="description" content="this is my page">
    <meta name="content-type" content="text/html; charset=UTF-8">
    <link rel="stylesheet" type="text/css" href="../pages/css/base.css">
    <link rel="stylesheet" type="text/css" href="../jqueryui/jquery-ui.css">
    <link rel="stylesheet" type="text/css" href="../src/css/layui.css">
    <link rel="stylesheet" type="text/css" href="../pages/css/mylayui.css">
    
  </head>
  
  <body>
    <div class="graph" style="height: 470px">
        <div class="graph-tools">
            <div class="graph-tools-inner">
                <button type="button" id="refreshBtn" class="layui-btn layui-btn-normal layui-btn-sm" title="刷新"><i class="layui-icon layui-icon-refresh-3"></i></button>
                <button type="button" id="exportBtn" class="layui-btn layui-btn-normal layui-btn-sm" title="导出"><i class="layui-icon layui-icon-file"></i></button>
            </div>
           </div>
        <div class="graph-content" id="tmpLine"></div>
    </div>
    <form action="../ExportTable.servlet" method="post" id="all_picture" enctype="multipart/form-data">
        <input type="hidden" name="PageName" value="autoPageName" />
        <input type="hidden" name="exp_picture_str" id="tmpLineGraph" />
        <input type="hidden" name="excelTitle" id="tblTitle" value="设备温度">
        <input type="hidden" name="table_th_arr" id="tblTh">
        <input type="hidden" name="table_td_arr" id="tblTd">
    </form>
    <script type="text/javascript" src="../js/jquery-1.8.3.js"></script>
    <script type="text/javascript" src="../js/base.js"></script>
    <script type="text/javascript" src="../js/echarts.js"></script>
    <script type="text/javascript" src="../src/layui.js"></script>
    <script type="text/javascript" src="../pages/js/mylayui.js"></script>
    <script type="text/javascript">
        layui.use(['form', 'table', 'layer', 'laydate','element'], function() {
            var table = layui.table;        // 获取表格模块
               var form = layui.form;            // 获取表单模块
               var layer = layui.layer;        // 获取弹出框模块
               var laydate = layui.laydate;    // 获取日期模块
               var element = layui.element;    // 获取元素操作模块
               var tmpLineGraph = echarts.init($('#tmpLine').get(0));
               createPageLine([], []);
               $(window).resize(function() {
                   tmpLineGraph.resize();
               });
               
               var table_th = ['记录时间', '设备温度'];
               var table_td = [];
               
               var lineGraphParams = parent.$('#lineGraphData').data('data');
               if(lineGraphParams) {
                   searchTmpData(lineGraphParams);
               }
               
               // graph tools btn的事件
               $("#refreshBtn").click(function() {
                   if(lineGraphParams) {
                       searchTmpData(lineGraphParams);
                   }
               });
               
               $("#exportBtn").click(function() {
                   if(lineGraphParams) {
                       exportData(lineGraphParams);
                   };
               });
               // 查询温度统计
            function searchTmpData(params) {
                var searchParams = {
                    dev_id: params.dev_id,
                    recordtime: params.startTime,
                    recordtime1: params.endTime,
                };
                //console.log(searchParams);
                var loading = layer.load(1);
                $.ajax({
                    type: 'post',
                    async: true,
                    url: 'Devtmp_recordAction!serchByCondition',
                    data: 'json='+JSON.stringify(searchParams),
                    dataType: 'json',
                    success: function(res) {
                        var rs = JSON.parse(res.result);
                        //console.log(rs);
                        // 判断是否查询成功
                        table_td = [];
                        var xdata = [];
                        var sdata = [];
                        if(rs.code == 1) {
                            var data = rs.data;
                            for(var i=0; i<data.length; i++) {
                                var _data = data[i];
                                xdata.push(_data.recordtime);
                                sdata.push(_data.dev_tmp);
                                table_td.push(_data.recordtime);
                                table_td.push(_data.dev_tmp);
                            }
                        }
                        createPageLine(xdata, sdata);
                    },
                    complete: function() {
                        layer.close(loading);
                    }
                });
            }
               
               // 生成折线图
            function createPageLine(xdata, sdata) {
                var min,max;
                if(xdata.length == 0) {
                    min = 0;
                    max = 1;
                }else {
                    min = Math.floor(getMinFromArr(sdata)*0.9);
                    max = Math.ceil(getMaxFromArr(sdata)*1.1);
                }
                
                var option = {
                    title: {
                        text: '',
                        subtext: ''
                    },
                    tooltip: {
                        trigger: 'axis'
                    },
                    legend: {},
                    grid: {
                        top:'7%',
                        left: '5%',
                        right: '5%',
                        bottom: '7%'
                    },
                    toolbox: {
                        show: false,
                    },
                    xAxis:  {
                        type: 'category',
                        boundaryGap: false,
                        data: xdata
                    },
                    yAxis: {
                        min: min,
                        max: max,
                        type: 'value',
                        axisLabel: {
                            formatter: '{value} °C'
                        }
                    },
                    series: [
                        {
                            name:'设备温度',
                            type:'line',
                            data: sdata,
                            markPoint: {
                                data: [
                                    {type: 'max', name: '最大值'},
                                ]
                            },
                        }
                    ]    
                };
                tmpLineGraph.resize();
                tmpLineGraph.setOption(option);
            }
            
            // 导出报表
            function exportData(data) {
                var lineGraph = tmpLineGraph.getDataURL({
                    pixelRatio: 1,
                    backgroundColor: '#fff'
                });
                $('#tblTitle').val(data.stationname+'-设备温度');
                
                $('#tmpLineGraph').val(lineGraph);
                
                var tblThStr = table_th.join(',');
                var tblTdStr = table_td.join('&');
                $('#tblTh').val(tblThStr);
                $('#tblTd').val(tblTdStr);
                // console.log(lineGraph);
                $('#all_picture').submit();
            }
        });
    </script>
  </body>
</html>