radarChart.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <template>
  2. <div shadow="never" class="homeBoxCard">
  3. <div class="height260" id="radarChart" ref="radarChart" />
  4. </div>
  5. </template>
  6. <script>
  7. import { defineComponent, onMounted, watch } from 'vue'
  8. import * as echarts from 'echarts'
  9. export default defineComponent({
  10. name: 'RadarChart',
  11. props:{
  12. getTableData:Object,
  13. },
  14. setup(props) {
  15. // 读取数据 func
  16. const getData = async () => {
  17. // await store.dispatch("Home/queryWorksChartData");
  18. }
  19. function echarts2(){
  20. let myChart = echarts.init(document.getElementById('radarChart'))
  21. // 绘制图表
  22. myChart.setOption({
  23. backgroundColor: '#FFF',
  24. tooltip: {},
  25. grid: {
  26. left: '20',
  27. right: '40',
  28. top: '-20',
  29. bottom: '0',
  30. containLabel: true,
  31. },
  32. radar: {
  33. radius: '60%',
  34. center: ['50%', '55%'],
  35. splitNumber: 5,
  36. nameGap: '15',
  37. name: {
  38. textStyle: {
  39. color: '#a8a8a8',
  40. },
  41. },
  42. axisLine: {
  43. lineStyle: {
  44. color: '#ebebeb',
  45. },
  46. },
  47. splitLine: {
  48. lineStyle: {
  49. width: 1,
  50. color: '#ebebeb',
  51. },
  52. },
  53. splitArea: {
  54. areaStyle: {
  55. color: ['#f8f8f8', '#fff'].reverse(),
  56. },
  57. },
  58. indicator: [
  59. {
  60. name: '电压平衡度',
  61. max: 20,
  62. },
  63. {
  64. name: '电流平衡度',
  65. max: 20,
  66. },
  67. {
  68. name: '功率因数',
  69. max: 20,
  70. },
  71. {
  72. name: '电压合格率',
  73. max: 20,
  74. },
  75. {
  76. name: '负载率',
  77. max: 20,
  78. },
  79. ],
  80. },
  81. series: [
  82. {
  83. name: 'Title✍',
  84. type: 'radar',
  85. symbolSize: 12,
  86. itemStyle: {
  87. borderColor: '#ebebeb',
  88. borderWidth: 2,
  89. },
  90. areaStyle: {
  91. opacity: 0.3,
  92. },
  93. data: [
  94. {
  95. itemStyle: {
  96. color: '#5eb6db',
  97. },
  98. value: [props.getTableData.vtBalunQ?20:0,props.getTableData.elBalunQ?20:0, props.getTableData.cosQ?20:0, props.getTableData.uq?20:0, props.getTableData.iloadQ?20:0],
  99. },
  100. ],
  101. },
  102. ],
  103. })
  104. window.addEventListener('resize', () => {
  105. myChart.resize()
  106. })
  107. }
  108. const writeValue = (val) => {
  109. val
  110. getData()
  111. echarts2()
  112. }
  113. //监听变化
  114. watch(
  115. () => props.getTableData,
  116. (newVal, oldVal, clear) => {
  117. // 执行异步任务,并得到关闭异步任务的 id
  118. // console.log(newVal)
  119. let id = writeValue(newVal, oldVal)
  120. // 如果 watch 监听被重复执行了,则会先清除上次未完成的异步任务
  121. clear(() => clearTimeout(id))
  122. },
  123. { lazy: true }
  124. )
  125. onMounted(() => {
  126. getData()
  127. echarts2()
  128. })
  129. return {
  130. getData,
  131. echarts2
  132. }
  133. },
  134. })
  135. </script>
  136. <style lang="scss" scoped>
  137. .homeBoxCard {
  138. margin-bottom: 24px;
  139. :deep(.el-card__header) {
  140. padding-left: 12px;
  141. padding-right: 12px;
  142. }
  143. :deep(.el-card__body) {
  144. padding: 12px;
  145. font-size: 14px;
  146. line-height: 1.5715;
  147. }
  148. :deep(.el-divider) {
  149. margin: 8px 0;
  150. }
  151. .num {
  152. font-size: 30px;
  153. color: #515a6e;
  154. }
  155. .height260 {
  156. height: 260px;
  157. }
  158. }
  159. </style>