bzy_detail_echart.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  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. <div class="mui-card">
  101. <!--页眉,放置标题-->
  102. <div class="mui-card-header">
  103. <h5>保温仓温度(°C)</h5>
  104. </div>
  105. <!--内容区-->
  106. <div class="mui-card-content">
  107. <div class="chart" id="pieChart"></div>
  108. </div>
  109. </div>
  110. <!--筛选日历-->
  111. <!--<div class="searchHintBox">-->
  112. <div class="calendarBox" style="display:none">
  113. <p>开始时间:<input id="start" placeholder="Please Select ..." readonly /></p>
  114. <p>结束时间:<input id="end" placeholder="Please Select ..." readonly /></p>
  115. </div>
  116. <!--</div>-->
  117. </div>
  118. <script src="../js/jquery-2.1.0.js" type="text/javascript" charset="utf-8"></script>
  119. <script src="../js/mobiscroll.custom-3.0.0-beta6.min.js" type="text/javascript" charset="utf-8"></script>
  120. <script src="../js/echarts.js"></script>
  121. <script>
  122. var equipId;
  123. // 1基于准备好的dom,初始化echarts实例
  124. var lineChart = echarts.init(document.getElementById('lineChart'));
  125. // 指定图表的配置项和数据
  126. var lineOption = {
  127. tooltip: {
  128. trigger: 'axis',
  129. formatter: function(params) {
  130. if(params.length > 1) {
  131. var returnData = '';
  132. var time = '';
  133. for(var g in params) {
  134. time = params[g].axisValue;
  135. if(params[g].seriesIndex == 0 || params[g].seriesIndex == 1) {
  136. returnData += params[g].seriesName + ':' + params[g].value + '°C<br/>';
  137. }
  138. if(params[g].seriesIndex == 2 || params[g].seriesIndex == 3) {
  139. returnData += params[g].seriesName + ':' + params[g].value + 'V<br/>';
  140. }
  141. }
  142. return time + '<br/>' + returnData;
  143. }
  144. }
  145. },
  146. legend: {
  147. y:15,
  148. itemWidth: 15,
  149. itemHeight: 10,
  150. itemGap: 8,
  151. data: ['环境温度', '环境湿度'],
  152. textStyle: {
  153. fontSize: 12,
  154. }
  155. },
  156. grid: {
  157. left: '3%',
  158. right: '4%',
  159. bottom: '3%',
  160. containLabel: true
  161. },
  162. toolbox: {
  163. feature: {
  164. // saveAsImage: {}
  165. }
  166. },
  167. xAxis: {
  168. type: 'category',
  169. boundaryGap: false,
  170. data: []
  171. },
  172. yAxis: {
  173. type: 'value',
  174. data: []
  175. },
  176. dataZoom: [{
  177. type: 'inside',
  178. backgroundColor: "rgba(47,69,84,0)",
  179. }],
  180. series: [{
  181. name: '环境温度',
  182. type: 'line',
  183. data: [],
  184. itemStyle: {
  185. normal: {
  186. color: '#f87fff',
  187. shadowBlur: 1,
  188. shadowColor: '#f87fff',
  189. borderColor:'#f87fff',
  190. borderWidth:2,
  191. backgroundColor:'transparent'
  192. }
  193. },
  194. areaStyle: {normal: {
  195. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  196. offset: 0,
  197. color: '#f87fff'
  198. }, {
  199. offset: 1,
  200. color: 'rgba(0,0,0,0)'
  201. }]),
  202. }}
  203. },
  204. {
  205. name: '环境湿度',
  206. type: 'line',
  207. data: [],
  208. itemStyle: {
  209. normal: {
  210. color: '#fea84c',
  211. shadowBlur: 1,
  212. shadowColor: '#fea84c',
  213. borderColor:'#fea84c',
  214. borderWidth:2,
  215. backgroundColor:'transparent'
  216. }
  217. },
  218. areaStyle: {normal: {
  219. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  220. offset: 0,
  221. color: '#fea84c'
  222. }, {
  223. offset: 1,
  224. color: 'rgba(0,0,0,0)'
  225. }]),
  226. }}
  227. },
  228. ]
  229. };
  230. // 2基于准备好的dom,初始化echarts实例
  231. var barChart = echarts.init(document.getElementById('pieChart'));
  232. // 指定图表的配置项和数据
  233. var barOption = {
  234. tooltip: {
  235. trigger: 'axis',
  236. formatter: function(params) {
  237. var returnData = '';
  238. var time = '';
  239. for(var g in params) {
  240. time = params[g].axisValue;
  241. returnData += params[g].seriesName + ':' + params[g].value + '只';
  242. }
  243. return time + '<br/>' + returnData;
  244. }
  245. },
  246. legend: {
  247. // x: 'right', // 'center' | 'left' | {number},
  248. y:15,
  249. data: ['保温仓温度'],
  250. itemWidth: 15,
  251. itemHeight: 10,
  252. itemGap: 8,
  253. textStyle: {
  254. fontSize: 12,
  255. }
  256. },
  257. grid: {
  258. left: '3%',
  259. right: '4%',
  260. bottom: '3%',
  261. containLabel: true
  262. },
  263. toolbox: {
  264. feature: {
  265. // saveAsImage: {}
  266. }
  267. },
  268. xAxis: {
  269. type: 'category',
  270. boundaryGap: false,
  271. data: []
  272. },
  273. yAxis: {
  274. type: 'value',
  275. data: []
  276. },
  277. dataZoom: [{
  278. type: 'inside',
  279. backgroundColor: "rgba(47,69,84,0)",
  280. }],
  281. series: [{
  282. name: '保温仓温度',
  283. type: 'line',
  284. data: [],
  285. itemStyle: {
  286. normal: {
  287. color: '#00c1de',
  288. shadowBlur: 1,
  289. shadowColor: '#00c1de',
  290. borderColor:'#00c1de',
  291. borderWidth:2,
  292. backgroundColor:'transparent'
  293. }
  294. },
  295. areaStyle: {normal: {
  296. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  297. offset: 0,
  298. color: '#00c1de'
  299. }, {
  300. offset: 1,
  301. color: 'rgba(0,0,0,0)'
  302. }]),
  303. }}
  304. }]
  305. };
  306. mui.plusReady(function() {
  307. var self = plus.webview.currentWebview();
  308. equipId = self.equipId;
  309. //请求图表数据:
  310. $.ajax({
  311. url: 'http://120.27.222.26/bzy_report_detail_chart',
  312. type: 'post',
  313. data: {
  314. req: 'data',
  315. id: equipId,
  316. },
  317. success: function(data) {
  318. console.log(JSON.stringify(data));
  319. var temp = eval('(' + data + ')');
  320. var at = [],
  321. ah = [],
  322. time = [],
  323. pre_temp = [];
  324. for(var i = 0; i < temp.length; i++) {
  325. at.unshift(Number(temp[i].at).toFixed(1));
  326. ah.unshift(Number(temp[i].ah).toFixed(1));
  327. if(Number(temp[i].pre_temp)>100 || Number(temp[i].pre_temp)<-10){
  328. pre_temp.unshift(15);
  329. }else{
  330. pre_temp.unshift(Number(temp[i].pre_temp));
  331. }
  332. time.unshift(temp[i].tim);
  333. }
  334. lineOption.series[0].data = at;
  335. lineOption.series[1].data = ah;
  336. lineOption.xAxis.data = time;
  337. barOption.series[0].data = pre_temp;
  338. barOption.xAxis.data = time;
  339. if(!temp.length) {
  340. lineOption.series[0].data = [];
  341. lineOption.series[1].data = [];
  342. lineOption.xAxis.data = ['暂无数据'];
  343. barOption.series[0].data = [];
  344. barOption.xAxis.data = ['暂无数据'];
  345. }
  346. // 使用刚指定的配置项和数据显示图表。
  347. setTimeout(function() {
  348. lineChart.setOption(lineOption);
  349. barChart.setOption(barOption);
  350. })
  351. }
  352. })
  353. //日历
  354. mobiscroll.settings = {
  355. theme: 'ios'
  356. ,lang: 'zh',
  357. };
  358. $('#date').mobiscroll().range({
  359. startInput: '#start',
  360. endInput: '#end',
  361. onSet: function (event, inst) {
  362. var start = getYMDHMS(inst.getVal()[0]);
  363. var end = getYMDHMS(inst.getVal()[1]);
  364. //请求图表数据:
  365. $.ajax({
  366. url: 'http://120.27.222.26/bzy_report_detail_chart',
  367. type: 'post',
  368. data: {
  369. req: 'filter',
  370. id: equipId,
  371. begin: start,
  372. end: end,
  373. },
  374. success: function(data) {
  375. var temp = eval('(' + data + ')');
  376. var at = [],
  377. ah = [],
  378. time = [],
  379. pre_temp = [];
  380. for(var i = 0; i < temp.length; i++) {
  381. at.unshift(Number(temp[i].at).toFixed(1));
  382. ah.unshift(Number(temp[i].ah).toFixed(1));
  383. if(Number(temp[i].pre_temp)>100 || Number(temp[i].pre_temp)<-10){
  384. pre_temp.unshift(15);
  385. }else{
  386. pre_temp.unshift(Number(temp[i].pre_temp));
  387. }
  388. time.unshift(temp[i].tim);
  389. }
  390. lineOption.series[0].data = at;
  391. lineOption.series[1].data = ah;
  392. lineOption.xAxis.data = time;
  393. barOption.series[0].data = pre_temp;
  394. barOption.xAxis.data = time;
  395. if(!temp.length) {
  396. lineOption.series[0].data = [0];
  397. lineOption.series[1].data = [0];
  398. lineOption.xAxis.data = ['暂无数据'];
  399. barOption.series[0].data = [0];
  400. barOption.xAxis.data = ['暂无数据'];
  401. }
  402. // 使用刚指定的配置项和数据显示图表。
  403. setTimeout(function() {
  404. lineChart.setOption(lineOption);
  405. barChart.setOption(barOption);
  406. })
  407. }
  408. })
  409. },
  410. });
  411. function getYMDHMS(time) {
  412. var time = new Date(time);
  413. var year = time.getFullYear(),
  414. month = time.getMonth() + 1,
  415. date = time.getDate();
  416. if (month < 10) { month = '0' + month; }
  417. if (date < 10) { date = '0' + date; }
  418. return year+'/'+ month+'/'+ date //不想
  419. }
  420. })
  421. </script>
  422. </body>
  423. </html>