wsCharts.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <template>
  2. <div class="wsChartPage">
  3. <div id="wsChart"/>
  4. </div>
  5. </template>
  6. <script>
  7. import {getWindChats} from "@/api/biz/dataQuery/homePage";
  8. export default {
  9. name: "wsCharts",
  10. props: {
  11. cftInfo: {type: Object}
  12. },
  13. watch:{
  14. cftInfo: {
  15. // immediate: true,
  16. handler(value) {
  17. // 获取测风塔编号
  18. console.log(value)
  19. this.month = ''
  20. this.equipmentNo = value.equipmentNo
  21. this.getData(value.equipmentNo)
  22. }
  23. },
  24. },
  25. data() {
  26. return {
  27. month:'',
  28. equipmentNo:'',
  29. wsLoading: false,
  30. wsCharts: null
  31. }
  32. },
  33. destroyed() {
  34. if (!this.wsCharts) {
  35. return
  36. }
  37. if (this.wsCharts != null) {
  38. this.wsCharts.dispose()
  39. this.wsCharts = null
  40. }
  41. },
  42. methods: {
  43. /*获取风速曲线的数据*/
  44. getData(cftNo) {
  45. getWindChats({equipmentId: cftNo,month:this.month}).then(res => {
  46. // console.log(res.data)
  47. const timeList = res.data.time
  48. const chartData = res.data.chart
  49. let legend = []
  50. let series = []
  51. let selected = {} // 不展示全部层高
  52. let j = 0;
  53. for (let i = 0; i < chartData.length; i++) {
  54. if (i > 3) {
  55. selected[chartData[i].height + 'm'] = false
  56. }
  57. legend.push(chartData[i].height + 'm')
  58. series.push({
  59. name: chartData[i].height + 'm',
  60. type: 'line',
  61. symbol: "none",
  62. data: chartData[i].value,
  63. })
  64. }
  65. this.drawWsChart(timeList, legend, selected, series)
  66. }).catch(err => {
  67. this.$message.error('首页获取风速曲线异常:' + err)
  68. console.log('首页获取风速曲线异常:' + err)
  69. this.wsCharts.hideLoading();
  70. })
  71. },
  72. /*风速折线图*/
  73. drawWsChart(timeList, legend, selected, series) {
  74. if(this.wsCharts === null){
  75. this.wsCharts = this.$echarts.init(document.getElementById('wsChart'))
  76. }
  77. let option = {
  78. dataZoom:{
  79. type:'inside'
  80. },
  81. tooltip: {
  82. trigger: 'axis',
  83. transitionDuration: 0,//提示框浮层的移动动画过渡时间,单位是 s,设置为 0 的时候会紧跟着鼠标移动。
  84. },
  85. legend: {
  86. data: legend,
  87. selected: selected,
  88. textStyle: {
  89. color: '#eeeeee'
  90. },
  91. top: '3%'
  92. },
  93. grid: {
  94. top: '25%',
  95. left: '2%',
  96. right: '0',
  97. bottom: '.5%',
  98. containLabel: true
  99. },
  100. //color: ['#dd6b66', '#759aa0', '#e69d87', '#8dc1a9', '#ea7e53', '#eedd78', '#73a373', '#73b9bc', '#7289ab', '#91ca8c', '#f49f42'],
  101. color: ['#e098c7', '#8fd3e8', '#71669e', '#cc70af', '#7cb4cc','#f7f494','#f7c5a0','#d4a4eb','#d2f5a6','#cc70af'],
  102. xAxis: {
  103. type: 'category',
  104. // boundaryGap: false,
  105. axisLine: {
  106. lineStyle: {
  107. color: '#eeeeee'
  108. }
  109. },
  110. axisLabel: {
  111. color: '#eeeeee'
  112. },
  113. // data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
  114. data: timeList
  115. },
  116. yAxis: {
  117. type: 'value',
  118. name: '风速(m/s)',
  119. axisLine: {
  120. show:true,
  121. lineStyle: {
  122. color: '#eeeeee'
  123. }
  124. },
  125. axisLabel: {
  126. color: '#eeeeee',
  127. // formatter: '{value}m/s'
  128. }
  129. },
  130. series: series
  131. }
  132. this.wsCharts.setOption(option, true)
  133. this.wsCharts.hideLoading();
  134. window.addEventListener('resize', () => {
  135. if (this.wsCharts) {
  136. this.wsCharts.resize()
  137. }
  138. })
  139. },
  140. }
  141. }
  142. </script>
  143. <style scoped>
  144. .wsChartPage {
  145. }
  146. #wsChart {
  147. width: 95%;
  148. height: calc(35vh);
  149. }
  150. </style>