innerLineChart.vue 4.5 KB

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