cbd_pest_data.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title></title>
  6. <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
  7. <link href="https://cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.css" rel="stylesheet">
  8. <link href="../css/mui.min.css" rel="stylesheet" />
  9. <link rel="stylesheet" href="../css/reset.css" />
  10. <!--<link rel="stylesheet" href="../css/iconfont.css" />-->
  11. <link rel="stylesheet" href="../css/mobiscroll.custom-3.0.0-beta6.min.css">
  12. <link href="../css/common.css" rel="stylesheet" />
  13. <link href="../css/swiper.min.css" rel="stylesheet" />
  14. <style type="text/css">
  15. body,
  16. .qxzCategory {
  17. /*background: #7432fe;*/
  18. }
  19. .mui-bar-nav {
  20. box-shadow: 0 1px 6px #21b2e7;
  21. }
  22. .echart {
  23. /*background: linear-gradient(#21b2e7, #7600ff);*/
  24. }
  25. .currTime {
  26. /*background: #7432fe;*/
  27. background: #ddebf0;
  28. /*color: #fff;*/
  29. line-height: 33px;
  30. font-size: 14px;
  31. padding: 10px 0;
  32. /*border-bottom: 1px solid #c0c0c0 !important;*/
  33. }
  34. .wormCategory {
  35. width: 40%;
  36. /*color: #333;*/
  37. padding-left: 10px;
  38. /*background: #ddebf0;*/
  39. border: 1px solid #c0c0c0 !important;
  40. background: #fff url(../images/downArrows.png) no-repeat 95%;
  41. background-size: 30px;
  42. }
  43. </style>
  44. </head>
  45. <body>
  46. <header class="mui-bar mui-bar-nav">
  47. <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
  48. <h1 class="mui-title" id="title">测报灯害虫统计</h1>
  49. <a class="mui-icon mui-icon-search mui-pull-right" id="date"></a>
  50. <!--<a class="headRightIcon fa fa-search mui-pull-right" id="reloadEquip">查询</a>-->
  51. </header>
  52. <div class="mui-content">
  53. <div class="clearfix currTime">
  54. <!--<div class="fl" id="gatherTime">采集时间:2019-15-13 12:26:54</div>-->
  55. 害虫种类:
  56. <select name="" class="wormCategory" id="wormCategory">
  57. </select>
  58. <!--<div class="fr" id="lookmore">更多>> </div>-->
  59. </div>
  60. <div class="echart">
  61. <!-- 为ECharts准备一个具备大小(宽高)的Dom -->
  62. <div id="lineChart" style="height:400px"></div>
  63. </div>
  64. <div class="echart">
  65. <!-- 为ECharts准备一个具备大小(宽高)的Dom -->
  66. <div id="pieChart" style="height:300px"></div>
  67. </div>
  68. <div class="calendarBox" style="display:none">
  69. <p>开始时间:<input id="start" placeholder="Please Select ..." readonly /></p>
  70. <p>结束时间:<input id="end" placeholder="Please Select ..." readonly /></p>
  71. </div>
  72. </div>
  73. <script src="../js/mui.min.js"></script>
  74. <script src="../js/jquery-2.1.0.js"></script>
  75. <script src="../js/common.js"></script>
  76. <script src="../js/echarts.js"></script>
  77. <script src="../js/cbd_pest_library.js"></script>
  78. <script src="../js/mobiscroll.custom-3.0.0-beta6.min.js" type="text/javascript" charset="utf-8"></script>
  79. <!-- ECharts单文件引入 -->
  80. <!--<script src="http://echarts.baidu.com/build/dist/echarts.js"></script>-->
  81. <script type="text/javascript">
  82. var lineChart = echarts.init(document.getElementById('lineChart'));
  83. lineOption = {
  84. title: {
  85. text: '害虫变化趋势',
  86. textStyle: {
  87. color: '#029eef'
  88. }
  89. },
  90. legend: {
  91. 'top': '8px',
  92. data: []
  93. },
  94. tooltip: {
  95. trigger: 'axis',
  96. formatter: function(params) {
  97. if(params.length >= 1) {
  98. var returnData = '';
  99. var time = '';
  100. for(let g in params) {
  101. if(params[g].componentIndex == 0) {
  102. returnData += params[g].seriesName + ':' + params[g].value + 'RH<br/>';
  103. } else if(params[g].componentIndex == 1) {
  104. returnData += params[g].seriesName + ':' + params[g].value + '°C<br/>';
  105. } else {
  106. returnData += params[g].data[1] + '只<br/>';
  107. }
  108. time = params[g].axisValue;
  109. // returnData += params[g].seriesName + ':' + params[g].value + '<br/>';
  110. }
  111. return time + '<br/>' + returnData;
  112. }
  113. }
  114. },
  115. xAxis: {
  116. data: []
  117. },
  118. yAxis: {
  119. axisLine: {
  120. show: true
  121. },
  122. },
  123. toolbox: {
  124. left: 'center',
  125. },
  126. dataZoom : {
  127. type:'inside',
  128. },
  129. grid: {
  130. left: '3%',
  131. right: '4%',
  132. bottom: '6%',
  133. containLabel: true
  134. },
  135. series: []
  136. }
  137. window.onresize = function() {
  138. //当窗口发生变化时图表显示
  139. lineChart.resize();
  140. pieChart.resize();
  141. }
  142. var color = ['#2196f3', '#03a9f4', '#00bcd4', '#009688', '#4caf50', '#8bc34a', '#cddc39', '#bfaf2a', '#ffc107', '#ff9800', '#a6c791', '#ba91c7', '#ecd3a7', '#96f2e5', '#96b2f2'];
  143. var pieChart = echarts.init(document.getElementById('pieChart'));
  144. pieOption = {
  145. title: {
  146. text: '害虫比例',
  147. textStyle: {
  148. color: '#029eef'
  149. }
  150. },
  151. tooltip: {
  152. trigger: 'item',
  153. formatter: "{a} <br/>{b} : {c} ({d}%)"
  154. },
  155. legend: {
  156. orient: 'vertical',
  157. left: 'right',
  158. data: []
  159. },
  160. grid: {
  161. left: '3%',
  162. right: '4%',
  163. bottom: '6%',
  164. containLabel: true
  165. },
  166. series: [{
  167. name: '害虫种类',
  168. type: 'pie',
  169. radius: '55%',
  170. radius: ['50%', '70%'],
  171. data: [],
  172. itemStyle: {
  173. emphasis: {
  174. shadowBlur: 10,
  175. shadowOffsetX: 0,
  176. shadowColor: 'rgba(0, 0, 0, 0.5)'
  177. }
  178. }
  179. }]
  180. };
  181. var equipId;
  182. mui.plusReady(function() {
  183. var self = plus.webview.currentWebview();
  184. equipId = self.equipId;
  185. $('#currEquipId').html('ID:' + equipId);
  186. requestData('', '', '');
  187. //日历
  188. mobiscroll.settings = {
  189. theme: 'ios',
  190. lang: 'zh',
  191. };
  192. $('#date').mobiscroll().range({
  193. startInput: '#start',
  194. endInput: '#end',
  195. onSet: function(event, inst) {
  196. var start = getYMDHMS(inst.getVal()[0]);
  197. var end = getYMDHMS(inst.getVal()[1]);
  198. //请求图表数据:
  199. requestData('filter', start, end);
  200. },
  201. });
  202. function getYMDHMS(time) {
  203. var time = new Date(time);
  204. var year = time.getFullYear(),
  205. month = time.getMonth() + 1,
  206. date = time.getDate();
  207. if(month < 10) {
  208. month = '0' + month;
  209. }
  210. if(date < 10) {
  211. date = '0' + date;
  212. }
  213. return year + '-' + month + '-' + date //不想
  214. }
  215. })
  216. function requestData(req, begin, end) {
  217. console.log(req)
  218. console.log(begin)
  219. console.log(end)
  220. mui.ajax('http://120.27.222.26/pest_at_ah', {
  221. data: {
  222. req: req,
  223. e_id: equipId,
  224. tbegin: begin,
  225. tend: end,
  226. },
  227. dataType: 'json', //服务器返回json格式数据
  228. type: 'post', //HTTP请求类型
  229. timeout: 8000, //超时时间设置为10秒;
  230. beforeSend: function() {
  231. plus.nativeUI.showWaiting('请求中...');
  232. },
  233. complete: function() {
  234. plus.nativeUI.closeWaiting();
  235. },
  236. success: function(data) {
  237. console.log(JSON.stringify(data))
  238. wormEcharts(data)
  239. },
  240. error: function(xhr, type, errorThrown) {
  241. $('#currEquipId').hide();
  242. $('.detialBox').hide();
  243. $('#reloadEquip').hide();
  244. mui.toast('数据请求失败');
  245. }
  246. })
  247. }
  248. //折线统计处理
  249. function wormEcharts(dat) {
  250. var type = [],
  251. timelist = [],
  252. value = [],
  253. ath = [
  254. [],
  255. []
  256. ];
  257. var legend = ['温度', '湿度'],
  258. time = [],
  259. amount = []; //种类及时间
  260. var kindNum = dat.kind;
  261. if(dat.kind.length) {
  262. for(var i = 0; i < dat.kind.length; i++) {
  263. // legend.unshift(insect_dict[dat.kind[i]]);
  264. var arr = [];
  265. amount.unshift(arr)
  266. if(i == (dat.kind.length) - 1) {
  267. // console.log(legend)
  268. }
  269. }
  270. for(var i = 0; i < dat.dat.length; i++) {
  271. if(dat.dat[i].ah && dat.dat[i].at) {
  272. ath[0].unshift((dat.dat[i].at/10).toFixed(2)) //温度
  273. ath[1].unshift((dat.dat[i].ah/10).toFixed(2))
  274. timelist.unshift(dat.dat[i].time);
  275. if(dat.dat[i].result) {
  276. for(var j = 0; j < dat.dat[i].result.split('#').length; j++) {
  277. var serialNum = dat.dat[i].result.split('#')[j].split(',');
  278. if(type.indexOf(serialNum[0]) == -1) {
  279. var currval = [];
  280. currval.push(dat.dat[i].time)
  281. currval.push(serialNum[1])
  282. value.push([currval])
  283. type.push(serialNum[0])
  284. } else {
  285. value[type.indexOf(serialNum[0])].push([dat.dat[i].time, serialNum[1]])
  286. }
  287. }
  288. }
  289. }
  290. if(i == dat.dat.length - 1) {
  291. if(type.length) {
  292. var html = '';
  293. for(var z = 0; z < type.length; z++) {
  294. html += '<option value="' + z + '">' + insect_dict[type[z]] + '</option>'
  295. }
  296. $('#wormCategory').html(html)
  297. $('#wormCategory').on('change', function() {
  298. lineOption.series = [];
  299. for(var s = 0; s < 2; s++) {
  300. lineOption.series.unshift({
  301. name: legend[s],
  302. type: 'line',
  303. data: ath[s],
  304. itemStyle: {
  305. normal: {
  306. color: color[s],
  307. shadowBlur: 1,
  308. shadowColor: color[s],
  309. borderColor: color[s],
  310. borderWidth: 2,
  311. backgroundColor: 'transparent'
  312. }
  313. },
  314. areaStyle: {
  315. normal: {
  316. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  317. offset: 0,
  318. color: color[s]
  319. }, {
  320. offset: 1,
  321. color: 'rgba(255, 2555, 255, 0.2)'
  322. }]),
  323. }
  324. }
  325. });
  326. // pieSeriesData.push(eval(amount[s].join("+")));
  327. }
  328. lineOption.series.push({
  329. symbolSize: 20,
  330. data: value[$(this).val()],
  331. type: 'scatter',
  332. itemStyle: {
  333. normal: {
  334. shadowBlur: 10,
  335. shadowColor: 'rgba(120, 36, 50, 0.5)',
  336. shadowOffsetY: 5,
  337. color: new echarts.graphic.RadialGradient(0.4, 0.3, 1, [{
  338. offset: 0,
  339. color: 'rgb(251, 118, 123)'
  340. }, {
  341. offset: 1,
  342. color: 'rgb(204, 46, 72)'
  343. }])
  344. }
  345. }
  346. })
  347. lineOption.xAxis.data = timelist;
  348. lineChart.setOption(lineOption);
  349. })
  350. lineOption.series = [];
  351. for(var s = 0; s < 2; s++) {
  352. lineOption.series.unshift({
  353. name: legend[s],
  354. type: 'line',
  355. data: ath[s],
  356. itemStyle: {
  357. normal: {
  358. color: color[s],
  359. shadowBlur: 1,
  360. shadowColor: color[s],
  361. borderColor: color[s],
  362. borderWidth: 2,
  363. backgroundColor: 'transparent'
  364. }
  365. },
  366. areaStyle: {
  367. normal: {
  368. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  369. offset: 0,
  370. color: color[s]
  371. }, {
  372. offset: 1,
  373. color: 'rgba(255, 2555, 255, 0.2)'
  374. }]),
  375. }
  376. }
  377. });
  378. }
  379. lineOption.series.push({
  380. symbolSize: 20,
  381. data: value[0],
  382. type: 'scatter',
  383. itemStyle: {
  384. normal: {
  385. shadowBlur: 10,
  386. shadowColor: 'rgba(120, 36, 50, 0.5)',
  387. shadowOffsetY: 5,
  388. color: new echarts.graphic.RadialGradient(0.4, 0.3, 1, [{
  389. offset: 0,
  390. color: 'rgb(251, 118, 123)'
  391. }, {
  392. offset: 1,
  393. color: 'rgb(204, 46, 72)'
  394. }])
  395. }
  396. }
  397. })
  398. pieOption.series[0].data = [];
  399. var pieSeriesData = [];
  400. for(var ss = 0; ss < value.length; ss++) {
  401. var totalwormnum = 0;
  402. for(var jj = 0; jj < value[ss].length; jj++) {
  403. totalwormnum += parseInt(value[ss][jj][1])
  404. if(jj == value[ss].length - 1) {
  405. pieSeriesData.push(totalwormnum);
  406. }
  407. }
  408. if(ss == value.length - 1) {
  409. for(var a = 0; a < type.length; a++) {
  410. var data = '{ value:' + pieSeriesData[a] + ', name:"' + insect_dict[type[a]] + '"}';
  411. pieOption.series[0].data.push(eval('(' + data + ')'));
  412. }
  413. }
  414. }
  415. $('#line-chart').prev().html('').css('z-index', 0);
  416. $('#pie-chart').prev().html('').css('z-index', 0);
  417. lineOption.xAxis.data = timelist;
  418. lineChart.setOption(lineOption);
  419. pieChart.setOption(pieOption);
  420. } else {
  421. lineOption.series = [];
  422. lineOption.xAxis.data = [];
  423. pieOption.series[0].data = [];
  424. lineChart.setOption(lineOption);
  425. pieChart.setOption(pieOption);
  426. $('#line-chart').prev().html('暂无害虫数据').css('z-index', 99);
  427. $('#pie-chart').prev().html('暂无害虫数据').css('z-index', 99);
  428. $('#wormType').html('<option value="">暂无害虫种类</option>')
  429. }
  430. }
  431. }
  432. }
  433. if(!dat.kind.length) {
  434. if(lineOption.series[0]) {
  435. lineOption.series[0].data = [];
  436. lineOption.series[1].data = [];
  437. } else {
  438. lineOption.series = [];
  439. }
  440. lineOption.xAxis.data = [];
  441. pieOption.series[0].data = [];
  442. lineChart.setOption(lineOption);
  443. pieChart.setOption(pieOption);
  444. $('#line-chart').prev().html('暂无害虫数据').css('z-index', 99);
  445. $('#pie-chart').prev().html('暂无害虫数据').css('z-index', 99);
  446. $('#wormCategory').html('<option value="">暂无害虫种类</option>')
  447. }
  448. }
  449. </script>
  450. </body>
  451. </html>