cbd_detail_echart.html 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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/common.css">
  12. <style>
  13. body,
  14. .mui-content {
  15. background-color: #ffffff;
  16. }
  17. .mui-card {
  18. position: fixed;
  19. left: 0;
  20. right: 0;
  21. top: 45px;
  22. bottom: 0;
  23. }
  24. .chart,
  25. .mui-card-content {
  26. /*height: 450px;*/
  27. margin: 0px;
  28. padding: 0px;
  29. position: absolute;
  30. left: 0;
  31. right: 0;
  32. top: 45px;
  33. bottom: 0;
  34. /*min-height: 450px;
  35. min-width: 320px;*/
  36. }
  37. h5 {
  38. margin-top: 30px;
  39. font-weight: bold;
  40. }
  41. h5:first-child {
  42. margin-top: 0;
  43. font-weight: 100;
  44. }
  45. .mui-switch.mui-active:before{
  46. content: "横屏";
  47. }
  48. .mui-switch:before {
  49. content: "竖屏";
  50. }
  51. .mui-switch.mui-active {
  52. border-color: #89dfff;
  53. background-color: #24b2e7;
  54. }
  55. </style>
  56. <script src="../js/mui.min.js"></script>
  57. </head>
  58. <body>
  59. <header class="mui-bar mui-bar-nav">
  60. <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
  61. <h1 class="mui-title">详情</h1>
  62. </header>
  63. <div class="mui-content">
  64. <!--<div class="mui-card">-->
  65. <!--页眉,放置标题-->
  66. <div class="mui-card-header">
  67. <h5>环境温度(°C)</h5>
  68. <!--<button id="switchBtn">竖屏</button>-->
  69. <!--<div class="mui-switch">
  70. <div class="mui-switch-handle"></div>
  71. </div>-->
  72. </div>
  73. <!--内容区-->
  74. <div class="mui-card-content">
  75. <div class="chart" id="lineChart"></div>
  76. </div>
  77. <!--</div>-->
  78. </div>
  79. <script src="../js/mui.min.js" type="text/javascript" charset="utf-8"></script>
  80. <script src="../js/jquery-2.1.0.js" type="text/javascript" charset="utf-8"></script>
  81. <script src="../js/echarts.min.js"></script>
  82. <script>
  83. mui.plusReady(function() {
  84. var self = plus.webview.currentWebview();
  85. equipId = self.equipId;
  86. console.log(equipId)
  87. // 1基于准备好的dom,初始化echarts实例
  88. var lineChart = echarts.init(document.getElementById('lineChart'));
  89. // 指定图表的配置项和数据
  90. var lineOption = {
  91. tooltip: {
  92. trigger: 'axis',
  93. extraCssText: 'transform: rotate(90deg)',
  94. formatter: function(params) {
  95. if(params.length > 1) {
  96. var returnData = '';
  97. var time = '';
  98. for(var g in params) {
  99. time = params[g].axisValue;
  100. returnData += params[g].seriesName + ':' + params[g].value + '°C<br/>';
  101. }
  102. return time + '<br/>' + returnData;
  103. }
  104. }
  105. },
  106. legend: {
  107. data: ['环境温度', '环境湿度'],
  108. },
  109. xAxis: {
  110. type: 'value', //数据
  111. position: 'top', //x 轴的位置【top bottom】
  112. nameRotate: -90, //坐标轴名字旋转,角度值。
  113. axisLabel: { //坐标轴刻度标签的相关设置。
  114. rotate: 90 //刻度标签旋转的角度,
  115. },
  116. scale: true, //是否是脱离 0 值比例
  117. },
  118. dataZoom: [{
  119. type: 'inside',
  120. backgroundColor: "rgba(47,69,84,0)",
  121. yAxisIndex: [0]
  122. }],
  123. yAxis: {
  124. type: 'category',
  125. inverse: 'true', //是否是反向坐标轴。
  126. axisLabel: {
  127. rotate: -90
  128. },
  129. type: 'category',
  130. boundaryGap: false,
  131. },
  132. series: [{
  133. name: '环境温度',
  134. type: 'line',
  135. smooth: true, //是否平滑曲线显示
  136. itemStyle: {
  137. normal: {
  138. color: '#6ecdfe'
  139. }
  140. }
  141. }, {
  142. name: '环境湿度',
  143. type: 'line',
  144. smooth: true, //是否平滑曲线显示
  145. itemStyle: {
  146. normal: {
  147. color: '#5689f2'
  148. }
  149. }
  150. }]
  151. };
  152. //请求图表数据:
  153. $.ajax({
  154. url: 'http://120.27.222.26/cbd_report_detail_chart',
  155. type: 'post',
  156. data: {
  157. req: 'data',
  158. id:equipId
  159. },
  160. success: function(data) {
  161. console.log(data)
  162. // sessionStorage.setItem("scdData", data);
  163. var temp = eval('(' + data + ')');
  164. var at = [],
  165. ah = [],
  166. time = [],
  167. cv = [],
  168. bv = [],
  169. ct = [];
  170. for(var i = 0; i < temp.length; i++) {
  171. at.unshift(Number(temp[i].at / 10).toFixed(1));
  172. ah.unshift(Number(temp[i].ah / 10).toFixed(1));
  173. cv.unshift((Number(temp[i].cv) / 1000).toFixed(1));
  174. bv.unshift((Number(temp[i].bv) / 1000).toFixed(1));
  175. ct.unshift(Number(temp[i].ct));
  176. time.unshift(temp[i].tim);
  177. }
  178. lineOption.series[0].data = at;
  179. lineOption.series[1].data = ah;
  180. lineOption.yAxis.data = time;
  181. if(!temp.length) {
  182. lineOption.series[0].data = [0];
  183. lineOption.yAxis.data = ['暂无数据'];
  184. }
  185. // 使用刚指定的配置项和数据显示图表。
  186. setTimeout(function() {
  187. lineChart.setOption(lineOption);
  188. })
  189. }
  190. })
  191. })
  192. </script>
  193. </body>
  194. </html>