cbd_detail_echart.html 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. if(params[g].seriesIndex == 0){
  101. returnData += params[g].seriesName + ':' + params[g].value + '°C<br/>';
  102. }else{
  103. returnData += params[g].seriesName + ':' + params[g].value + '%<br/>';
  104. }
  105. }
  106. return time + '<br/>' + returnData;
  107. }
  108. }
  109. },
  110. legend: {
  111. data: ['环境温度', '环境湿度'],
  112. },
  113. xAxis: {
  114. type: 'value', //数据
  115. position: 'top', //x 轴的位置【top bottom】
  116. nameRotate: -90, //坐标轴名字旋转,角度值。
  117. axisLabel: { //坐标轴刻度标签的相关设置。
  118. rotate: 90 //刻度标签旋转的角度,
  119. },
  120. scale: true, //是否是脱离 0 值比例
  121. },
  122. dataZoom: [{
  123. type: 'inside',
  124. backgroundColor: "rgba(47,69,84,0)",
  125. yAxisIndex: [0]
  126. }],
  127. yAxis: {
  128. type: 'category',
  129. inverse: 'true', //是否是反向坐标轴。
  130. axisLabel: {
  131. rotate: -90
  132. },
  133. type: 'category',
  134. boundaryGap: false,
  135. },
  136. series: [{
  137. name: '环境温度',
  138. type: 'line',
  139. smooth: true, //是否平滑曲线显示
  140. itemStyle: {
  141. normal: {
  142. color: '#6ecdfe'
  143. }
  144. }
  145. }, {
  146. name: '环境湿度',
  147. type: 'line',
  148. smooth: true, //是否平滑曲线显示
  149. itemStyle: {
  150. normal: {
  151. color: '#5689f2'
  152. }
  153. }
  154. }]
  155. };
  156. //请求图表数据:
  157. $.ajax({
  158. url: 'http://120.27.222.26/cbd_report_detail_chart',
  159. type: 'post',
  160. data: {
  161. req: 'data',
  162. id:equipId
  163. },
  164. success: function(data) {
  165. console.log(data)
  166. // sessionStorage.setItem("scdData", data);
  167. var temp = eval('(' + data + ')');
  168. var at = [],
  169. ah = [],
  170. time = [],
  171. cv = [],
  172. bv = [],
  173. ct = [];
  174. for(var i = 0; i < temp.length; i++) {
  175. at.unshift(Number(temp[i].at / 10).toFixed(1));
  176. ah.unshift(Number(temp[i].ah / 10).toFixed(1));
  177. cv.unshift((Number(temp[i].cv) / 1000).toFixed(1));
  178. bv.unshift((Number(temp[i].bv) / 1000).toFixed(1));
  179. ct.unshift(Number(temp[i].ct));
  180. time.unshift(temp[i].tim);
  181. }
  182. lineOption.series[0].data = at;
  183. lineOption.series[1].data = ah;
  184. lineOption.yAxis.data = time;
  185. if(!temp.length) {
  186. lineOption.series[0].data = [0];
  187. lineOption.yAxis.data = ['暂无数据'];
  188. }
  189. // 使用刚指定的配置项和数据显示图表。
  190. setTimeout(function() {
  191. lineChart.setOption(lineOption);
  192. })
  193. }
  194. })
  195. })
  196. </script>
  197. </body>
  198. </html>