index.html 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. <script src="https://s3.pstatp.com/cdn/expire-1-M/jquery/3.3.1/jquery.min.js"></script>
  9. <script src="./js/echarts.min.js"></script>
  10. <style>
  11. #echarts-weather {
  12. width: 800px;
  13. height: 400px;
  14. }
  15. </style>
  16. </head>
  17. <body style="margin: 0; text-align: center">
  18. <div id="he-plugin-standard" style="margin: 0 auto"></div>
  19. <div id="echarts-weather"></div>
  20. <script>
  21. WIDGET = {
  22. "CONFIG": {
  23. "layout": "1",
  24. "width": "800",
  25. "height": "400",
  26. "background": "1",
  27. "dataColor": "FFFFFF",
  28. "textAlign": 'center',
  29. "borderRadius": "0",
  30. "key": "bfab9d72ee5d4719a5e96fb50436c396"
  31. }
  32. }
  33. let farmId = localStorage.getItem('lastFarmId');
  34. const token = localStorage.getItem('accessToken');
  35. var myChart = echarts.init(document.getElementById('echarts-weather'))
  36. let options = {
  37. title: {
  38. text: '未来24小时温度变化',
  39. left: 'center',
  40. color: '#fff',
  41. textStyle : {
  42. color: '#fff'
  43. }
  44. },
  45. tooltip: {
  46. trigger: 'axis',
  47. },
  48. color: ['#FFFFFF'],
  49. xAxis: [
  50. {
  51. type: 'category',
  52. data: [],
  53. axisPointer: {
  54. type: 'shadow'
  55. },
  56. axisLine: {
  57. show: false,
  58. lineStyle: {
  59. color: '#fff',
  60. }
  61. },
  62. axisTick:{
  63. show:false
  64. },
  65. }
  66. ],
  67. yAxis: [
  68. {
  69. type: 'value',
  70. axisLabel: {
  71. formatter: '{value}℃'
  72. },
  73. axisLine: {
  74. show: false,
  75. lineStyle: {
  76. color: '#fff',
  77. }
  78. },
  79. axisTick:{
  80. show:false
  81. },
  82. }
  83. ],
  84. series: [
  85. {
  86. name: '温度',
  87. type: 'line',
  88. // stack: 'Total',
  89. smooth: true,
  90. areaStyle: {},
  91. emphasis: {
  92. focus: 'series'
  93. },
  94. itemStyle : {
  95. color: '#fff',
  96. borderColor: '#fff',
  97. normal: {
  98. label : {
  99. show: true,
  100. textStyle: {
  101. fontSize: 14
  102. }
  103. }
  104. }
  105. },
  106. data: []
  107. }
  108. ]
  109. }
  110. $.ajax({
  111. url: `http://120.27.234.126:8010/produce/weather/info?farmId=${farmId}`,
  112. type: 'POST',
  113. headers: {
  114. accessToken: token
  115. },
  116. success: function(res) {
  117. if(res.code === 10000) {
  118. options.series[0].data = res.data.tempList;
  119. let arr = [];
  120. res.data.timeList.forEach(item => {
  121. arr.push(item.substring(5, 16))
  122. })
  123. options.xAxis[0].data = arr;
  124. myChart.setOption(options)
  125. }
  126. }
  127. })
  128. </script>
  129. <script src="https://widget.qweather.net/standard/static/js/he-standard-common.js?v=2.0"></script>
  130. </body>
  131. </html>