innerLineChart.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <template>
  2. <div shadow="never" class="homeBoxCard" v-loading="loading">
  3. <div class="height400" ref="lineChartBanlance" />
  4. </div>
  5. </template>
  6. <script>
  7. import { useStore } from 'vuex'
  8. import { defineComponent, onMounted, ref, watch } from 'vue'
  9. import * as echarts from 'echarts'
  10. export default defineComponent({
  11. name: 'lineChartValue',
  12. props: {},
  13. setup(props) {
  14. props
  15. const store = useStore()
  16. let lineChartBanlance = ref(null)
  17. const dataTimes = ref([])
  18. const lineChartArr = ref([])
  19. // 读取数据 func
  20. const loading = ref(true)
  21. const getData = async () => {
  22. dataTimes.value = store.state.realScoreLineDataTime
  23. lineChartArr.value = store.state.realScoreLineObj
  24. lineChartArr.value.forEach((value) => {
  25. value.type = 'line'
  26. value.smooth = false
  27. value.symbolSize = 7
  28. // value.markPoint = {
  29. // data: [
  30. // { type: 'max', name: 'Max' },
  31. // { type: 'min', name: 'Min' },
  32. // ],
  33. // }
  34. })
  35. loading.value = false
  36. }
  37. function echarts2() {
  38. let myChart = echarts.init(lineChartBanlance.value)
  39. // 绘制图表
  40. myChart.setOption({
  41. color: ['#1187FF', '#48C964', '#fe8161'],
  42. legend: {
  43. top: '0',
  44. },
  45. tooltip: {
  46. // show: true
  47. trigger: 'axis',
  48. axisPointer: { type: 'cross' },
  49. },
  50. grid: {
  51. left: '20',
  52. right: '40',
  53. top: '40',
  54. bottom: '30',
  55. containLabel: true,
  56. },
  57. xAxis: {
  58. axisLabel: {
  59. color: '#444',
  60. fontSize: 14,
  61. },
  62. /*改变xy轴颜色*/
  63. axisLine: {
  64. lineStyle: {
  65. color: '#444',
  66. width: 1, //这里是为了突出显示加上的
  67. },
  68. },
  69. boundaryGap: false,
  70. data: dataTimes.value,
  71. },
  72. yAxis: {
  73. name: store.state.realScoreLineName,
  74. textStyle: {
  75. color: 'black',
  76. fontSize: 10,
  77. },
  78. type: 'value',
  79. axisTick: {
  80. show: true, //去除刻度线
  81. },
  82. axisLabel: {
  83. color: 'black', // 文本颜色
  84. },
  85. axisLine: {
  86. show: true, // 去除轴线
  87. lineStyle: {
  88. color: 'black',
  89. },
  90. },
  91. splitNumber: 5,
  92. splitLine: {
  93. show: true,
  94. lineStyle: {
  95. color: '#9d9d9d',
  96. },
  97. },
  98. },
  99. // series: [
  100. // {
  101. // name: 'A相电流',
  102. // type: 'line',
  103. // symbolSize: 7,
  104. // smooth: false,
  105. // data: [1, 2, 6, 4, 5, 58, 6, 7, 8],
  106. // },
  107. // {
  108. // name: 'B相电流',
  109. // type: 'line',
  110. // symbolSize: 7,
  111. // smooth: false,
  112. // data: [1, 2, 3, 4, 9, 5, 6, 7, 8],
  113. // },
  114. // {
  115. // name: 'C相电流',
  116. // type: 'line',
  117. // symbolSize: 7,
  118. // smooth: false,
  119. // data: [1, 2, 3, 4, 5, 6, 6, 7, 3],
  120. // },
  121. // ],
  122. series: lineChartArr.value,
  123. })
  124. window.addEventListener('resize', () => {
  125. myChart.resize()
  126. })
  127. }
  128. const writeValue = (val) => {
  129. val
  130. getData()
  131. echarts2()
  132. }
  133. //监听变化
  134. watch(
  135. () => store.state.realScoreLineObj,
  136. (newVal, oldVal, clear) => {
  137. // 执行异步任务,并得到关闭异步任务的 id
  138. // console.log(newVal)
  139. let id = writeValue(newVal, oldVal)
  140. // 如果 watch 监听被重复执行了,则会先清除上次未完成的异步任务
  141. clear(() => clearTimeout(id))
  142. },
  143. { lazy: true }
  144. )
  145. onMounted(() => {
  146. // getData()
  147. // echarts2()
  148. })
  149. return {
  150. lineChartBanlance,
  151. loading,
  152. store,
  153. dataTimes,
  154. lineChartArr,
  155. }
  156. },
  157. })
  158. </script>
  159. <style lang="scss" scoped>
  160. .homeBoxCard {
  161. margin-bottom: 24px;
  162. ::v-deep(.el-card__header) {
  163. padding-left: 12px;
  164. padding-right: 12px;
  165. }
  166. ::v-deep(.el-card__body) {
  167. padding: 12px;
  168. font-size: 14px;
  169. line-height: 1.5715;
  170. }
  171. ::v-deep(.el-divider) {
  172. margin: 8px 0;
  173. }
  174. .num {
  175. font-size: 30px;
  176. color: #515a6e;
  177. }
  178. .height400 {
  179. height: 400px;
  180. }
  181. }
  182. </style>