sex_trap_detail_echart.html 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>ECahrt 示例</title>
  6. <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
  7. <meta name="apple-mobile-web-app-capable" content="yes">
  8. <meta name="apple-mobile-web-app-status-bar-style" content="black">
  9. <link href="https://cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.css" rel="stylesheet">
  10. <link rel="stylesheet" href="../css/mui.min.css">
  11. <link rel="stylesheet" href="../css/mobiscroll.custom-3.0.0-beta6.min.css">
  12. <link rel="stylesheet" href="../css/common.css">
  13. <style>
  14. /*body,
  15. .mui-content {
  16. background-color: #ffffff;
  17. }
  18. */
  19. .chart {
  20. height: 250px;
  21. margin: 0px;
  22. padding: 0px;
  23. }
  24. h5 {
  25. margin-top: 30px;
  26. font-weight: bold;
  27. }
  28. h5:first-child {
  29. margin-top: 0;
  30. font-weight: 100;
  31. }
  32. /*tab*/
  33. .mui-segmented-control {
  34. border: none;
  35. display: inherit;
  36. overflow: visible;
  37. margin: 20px 0;
  38. background-color: #fff;
  39. }
  40. .mui-segmented-control .mui-control-item {
  41. border-left: none;
  42. color: #333;
  43. overflow: visible;
  44. }
  45. .mui-segmented-control .mui-control-item.mui-active {
  46. color: #333;
  47. background: transparent;
  48. border-bottom: none;
  49. position: relative;
  50. }
  51. .mui-control-item.mui-active:before {
  52. content: '';
  53. position: absolute;
  54. left: 50%;
  55. bottom: -3px;
  56. width: 70px;
  57. background: #007aff;
  58. height: 3px;
  59. margin-left: -35px;
  60. }
  61. .mui-control-item.mui-active:after {
  62. content: '';
  63. position: absolute;
  64. left: 50%;
  65. border: 26px solid #007aff;
  66. bottom: -18px;
  67. margin-left: -5px;
  68. border-top: #007aff 5px solid;
  69. border-left: transparent 5px solid;
  70. border-bottom: transparent 10px solid;
  71. border-right: transparent 5px solid;
  72. }
  73. .mui-segmented-control .mui-control-item {
  74. line-height: 30px;
  75. }
  76. .mui-control-item.mui-active {
  77. color: #333;
  78. border-bottom: 3px solid #007AFF;
  79. }
  80. </style>
  81. <script src="../js/mui.min.js"></script>
  82. </head>
  83. <body>
  84. <header class="mui-bar mui-bar-nav">
  85. <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
  86. <h1 class="mui-title">详情</h1>
  87. <a class="mui-icon mui-icon-search mui-pull-right" id="date"></a>
  88. </header>
  89. <div class="mui-content">
  90. <div class="mui-card">
  91. <!--页眉,放置标题-->
  92. <div class="mui-card-header">
  93. <h5>温度(°C)湿度(%)</h5>
  94. </div>
  95. <!--内容区-->
  96. <div class="mui-card-content">
  97. <div class="chart" id="lineChart"></div>
  98. </div>
  99. </div>
  100. <!--<h5>击虫次数</h5>-->
  101. <div class="mui-card">
  102. <!--页眉,放置标题-->
  103. <div class="mui-card-header">
  104. <h5>CPU温度(°C)</h5>
  105. </div>
  106. <!--内容区-->
  107. <div class="mui-card-content">
  108. <div class="chart" id="pieChart"></div>
  109. </div>
  110. </div>
  111. <!--筛选日历-->
  112. <!--<div class="searchHintBox">-->
  113. <div class="calendarBox" style="display:none">
  114. <p>开始时间:<input id="start" placeholder="Please Select ..." readonly /></p>
  115. <p>结束时间:<input id="end" placeholder="Please Select ..." readonly /></p>
  116. </div>
  117. <!--</div>-->
  118. </div>
  119. <script src="../js/jquery-2.1.0.js" type="text/javascript" charset="utf-8"></script>
  120. <script src="../js/mobiscroll.custom-3.0.0-beta6.min.js" type="text/javascript" charset="utf-8"></script>
  121. <script src="../js/echarts.min.js"></script>
  122. <script>
  123. var equipId;
  124. // 1基于准备好的dom,初始化echarts实例
  125. var lineChart = echarts.init(document.getElementById('lineChart'));
  126. // 指定图表的配置项和数据
  127. var lineOption = {
  128. tooltip: {
  129. trigger: 'axis',
  130. formatter: function(params) {
  131. if(params.length > 1) {
  132. var returnData = '';
  133. var time = '';
  134. for(var g in params) {
  135. time = params[g].axisValue;
  136. if(params[g].seriesIndex == 0 || params[g].seriesIndex == 1) {
  137. returnData += params[g].seriesName + ':' + params[g].value + '°C<br/>';
  138. }
  139. if(params[g].seriesIndex == 2 || params[g].seriesIndex == 3) {
  140. returnData += params[g].seriesName + ':' + params[g].value + 'V<br/>';
  141. }
  142. }
  143. return time + '<br/>' + returnData;
  144. }
  145. }
  146. },
  147. legend: {
  148. y:15,
  149. itemWidth: 15,
  150. itemHeight: 10,
  151. itemGap: 8,
  152. data: ['环境温度', '环境湿度'],
  153. textStyle: {
  154. fontSize: 12,
  155. }
  156. },
  157. grid: {
  158. left: '3%',
  159. right: '4%',
  160. bottom: '3%',
  161. containLabel: true
  162. },
  163. toolbox: {
  164. feature: {
  165. // saveAsImage: {}
  166. }
  167. },
  168. xAxis: {
  169. type: 'category',
  170. boundaryGap: false,
  171. data: [1, 2, 3, 4, 5, 6, 7]
  172. },
  173. yAxis: {
  174. type: 'value',
  175. data: [20, 30, 52, 20, 64, 56, 80]
  176. },
  177. dataZoom: [{
  178. type: 'inside',
  179. backgroundColor: "rgba(47,69,84,0)",
  180. }],
  181. series: [{
  182. name: '环境温度',
  183. type: 'line',
  184. data: [20, 30, 52, 20, 64, 56, 80],
  185. itemStyle: {
  186. normal: {
  187. color: '#6ecdfe'
  188. }
  189. }
  190. },
  191. {
  192. name: '环境湿度',
  193. type: 'line',
  194. data: [],
  195. itemStyle: {
  196. normal: {
  197. color: '#5689f2'
  198. }
  199. }
  200. }
  201. ]
  202. };
  203. // 2基于准备好的dom,初始化echarts实例
  204. var barChart = echarts.init(document.getElementById('pieChart'));
  205. // 指定图表的配置项和数据
  206. var barOption = {
  207. tooltip: {
  208. trigger: 'axis',
  209. formatter: function(params) {
  210. var returnData = '';
  211. var time = '';
  212. for(var g in params) {
  213. time = params[g].axisValue;
  214. returnData += params[g].seriesName + ':' + params[g].value + '只';
  215. }
  216. return time + '<br/>' + returnData;
  217. }
  218. },
  219. legend: {
  220. // x: 'right', // 'center' | 'left' | {number},
  221. y:15,
  222. data: ['CUP温度'],
  223. itemWidth: 15,
  224. itemHeight: 10,
  225. itemGap: 8,
  226. textStyle: {
  227. fontSize: 12,
  228. }
  229. },
  230. grid: {
  231. left: '3%',
  232. right: '4%',
  233. bottom: '3%',
  234. containLabel: true
  235. },
  236. toolbox: {
  237. feature: {
  238. // saveAsImage: {}
  239. }
  240. },
  241. xAxis: {
  242. type: 'category',
  243. boundaryGap: false,
  244. data: []
  245. },
  246. yAxis: {
  247. type: 'value',
  248. data: []
  249. },
  250. dataZoom: [{
  251. type: 'inside',
  252. backgroundColor: "rgba(47,69,84,0)",
  253. }],
  254. series: [{
  255. name: 'CUP温度',
  256. type: 'line',
  257. data: [],
  258. itemStyle: {
  259. normal: {
  260. color: '#6ecdfe'
  261. }
  262. }
  263. }]
  264. };
  265. mui.plusReady(function() {
  266. var self = plus.webview.currentWebview();
  267. equipId = self.equipId;
  268. //请求图表数据:
  269. $.ajax({
  270. url: 'http://120.27.222.26/sex_at_ah',
  271. type: 'post',
  272. data: {
  273. begin: '',
  274. end: '',
  275. e_id: equipId
  276. },
  277. dataType:'json',
  278. success: function(data) {
  279. sessionStorage.setItem("scdData", data);
  280. var temp = data;
  281. var at = [],
  282. ah = [],
  283. time = [],
  284. cpu_tmp = [];
  285. for(var i = 0; i < temp.length; i++) {
  286. at.unshift(Number(temp[i].at).toFixed(1));
  287. ah.unshift(Number(temp[i].ah).toFixed(1));
  288. cpu_tmp.unshift((Number(temp[i].cpu_tmp) / 1000).toFixed(1));
  289. time.unshift(temp[i].tim);
  290. }
  291. lineOption.series[0].data = at;
  292. lineOption.series[1].data = ah;
  293. lineOption.xAxis.data = time;
  294. barOption.series[0].data = cpu_tmp;
  295. barOption.xAxis.data = time;
  296. if(!temp.length) {
  297. lineOption.series[0].data = [0];
  298. lineOption.series[1].data = [0];
  299. lineOption.xAxis.data = ['暂无数据'];
  300. barOption.series[0].data = [0];
  301. barOption.xAxis.data = ['暂无数据'];
  302. }
  303. // 使用刚指定的配置项和数据显示图表。
  304. setTimeout(function() {
  305. lineChart.setOption(lineOption);
  306. barChart.setOption(barOption);
  307. })
  308. }
  309. })
  310. //日历
  311. mobiscroll.settings = {
  312. theme: 'ios'
  313. ,lang: 'zh',
  314. };
  315. $('#date').mobiscroll().range({
  316. startInput: '#start',
  317. endInput: '#end',
  318. onSet: function (event, inst) {
  319. var start = getYMDHMS(inst.getVal()[0]);
  320. var end = getYMDHMS(inst.getVal()[1]);
  321. //请求图表数据:
  322. $.ajax({
  323. url: 'http://120.27.222.26/sex_at_ah',
  324. type: 'post',
  325. data: {
  326. e_id: equipId,
  327. begin: start,
  328. end: end
  329. },
  330. success: function(data) {
  331. sessionStorage.setItem("scdData", data);
  332. var temp = data;
  333. var at = [],
  334. ah = [],
  335. time = [],
  336. cpu_tmp = [];
  337. for(var i = 0; i < temp.length; i++) {
  338. at.unshift(Number(temp[i].at).toFixed(1));
  339. ah.unshift(Number(temp[i].ah).toFixed(1));
  340. cpu_tmp.unshift((Number(temp[i].cpu_tmp) / 1000).toFixed(1));
  341. time.unshift(temp[i].tim);
  342. }
  343. lineOption.series[0].data = at;
  344. lineOption.series[1].data = ah;
  345. lineOption.xAxis.data = time;
  346. barOption.series[0].data = cpu_tmp;
  347. barOption.xAxis.data = time;
  348. if(!temp.length) {
  349. lineOption.series[0].data = [0];
  350. lineOption.series[1].data = [0];
  351. lineOption.xAxis.data = ['暂无数据'];
  352. barOption.series[0].data = [0];
  353. barOption.xAxis.data = ['暂无数据'];
  354. }
  355. // 使用刚指定的配置项和数据显示图表。
  356. setTimeout(function() {
  357. lineChart.setOption(lineOption);
  358. barChart.setOption(barOption);
  359. })
  360. }
  361. })
  362. },
  363. });
  364. function getYMDHMS(time) {
  365. var time = new Date(time);
  366. var year = time.getFullYear(),
  367. month = time.getMonth() + 1,
  368. date = time.getDate();
  369. if (month < 10) { month = '0' + month; }
  370. if (date < 10) { date = '0' + date; }
  371. return year+'/'+ month+'/'+ date //不想
  372. }
  373. })
  374. </script>
  375. </body>
  376. </html>