bzy_detail_echart.html 12 KB

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