chart.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <template>
  2. <img src="@/assets/main_top_left.png" alt="" class="imgStyle"/>
  3. <div class="titleIcon"></div>
  4. <div class="chartBox_title">温度/湿度</div>
  5. <div id="environment" class="environment"></div>
  6. </template>
  7. <script setup>
  8. import * as echarts from 'echarts';
  9. import { onMounted, watch } from 'vue'
  10. import { useScreenStore } from "@/pinia/modules/screen";
  11. const useScreen = useScreenStore()
  12. onMounted(() => {
  13. setTimeout(function (){
  14. const list = useScreen.tunnelList[0].envData
  15. chartLoading(list)
  16. }, 1000)
  17. })
  18. const chartLoading = (list) => {
  19. let myChart = echarts.init(document.getElementById('environment'));
  20. myChart.setOption({
  21. tooltip: {
  22. trigger: 'axis',
  23. axisPointer: {
  24. type: 'cross',
  25. crossStyle: {
  26. color: '#ffffff'
  27. }
  28. },
  29. },
  30. legend: {
  31. data: [
  32. // '待下发','处置中','已完成'
  33. {
  34. name: '温度',
  35. textStyle: {
  36. color: '#0EFCFF' // 图例文字颜色
  37. }
  38. },
  39. {
  40. name: '湿度',
  41. textStyle: {
  42. color: '#0EFCFF' // 图例文字颜色
  43. }
  44. }
  45. ],
  46. },
  47. xAxis: {
  48. type: 'time', // 使用时间类型的x轴
  49. boundaryGap: false,
  50. axisLine: {
  51. show:true,
  52. lineStyle:{
  53. color:'#0EFCFF',
  54. width:1,
  55. type:'solid'
  56. }
  57. }
  58. },
  59. yAxis: {
  60. axisLine: {
  61. show:true,
  62. lineStyle:{
  63. color:'#0EFCFF',
  64. width:1,
  65. type:'solid'
  66. }
  67. },
  68. splitLine: {
  69. lineStyle: {
  70. color: ['#0EFCFF']
  71. }
  72. }
  73. },
  74. series: [
  75. {
  76. name: '温度',
  77. type: 'line',
  78. data: list.map(item => [new Date(item.CreatedAt).getTime(), item.temperature])
  79. },
  80. {
  81. name: '湿度',
  82. type: 'line',
  83. data: list.map(item => [new Date(item.CreatedAt).getTime(), item.humidity])
  84. }
  85. ],
  86. })
  87. }
  88. // 监听 ref 数据变化
  89. watch(() => useScreen.currentTunnel, (newValue, oldValue) => {
  90. yourMethod(newValue) // 调用你的方法
  91. })
  92. const yourMethod = (value) => {
  93. chartLoading(value.envData)
  94. // 你的逻辑代码
  95. }
  96. </script>
  97. <style scoped lang="less">
  98. .imgStyle{
  99. width: 400px;
  100. height: 250px;
  101. }
  102. .titleIcon{
  103. width: 5px;
  104. height: 20px;
  105. background-color: #0EFCFF;
  106. position: absolute;
  107. left: 20px;
  108. top: 16px;
  109. }
  110. .chartBox_title{
  111. position: absolute;
  112. left: 30px;
  113. top: 15px;
  114. font-size: 20px;
  115. color: #0EFCFF;
  116. }
  117. .environment{
  118. width: 400px;
  119. height: 250px;
  120. position: absolute;
  121. left: 5px;
  122. top: 20px;
  123. }
  124. </style>