index.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <template>
  2. <div shadow="never" class="homeBoxCard">
  3. <div :style="'height:' + Height" id="sumeChartRef" ref="sumeChartRef" />
  4. </div>
  5. </template>
  6. <script>
  7. import { computed, defineComponent, onMounted, watch } from 'vue'
  8. import { useStore } from 'vuex'
  9. import * as echarts from 'echarts'
  10. // import { ChartDataType } from "../../data";
  11. export default defineComponent({
  12. name: 'CurveCom',
  13. props: {
  14. Height: String,
  15. echartsData: Object,
  16. },
  17. setup(props) {
  18. const store = useStore()
  19. // 总数
  20. const total = computed(() => store.state.Home.worksChartData.total)
  21. // num
  22. const num = computed(() => store.state.Home.worksChartData.num)
  23. // 读取数据 func
  24. const getData = async () => {
  25. console.log('ecahrts子组件中的props.ecahrtsData')
  26. console.log(props.echartsData)
  27. }
  28. function echarts2() {
  29. let myChart = echarts.init(document.getElementById('sumeChartRef'))
  30. // 绘制图表
  31. myChart.setOption({
  32. color: ['#FEB70D', '#50F335', '#0DC8FE'],
  33. tooltip: {
  34. trigger: 'axis',
  35. },
  36. toolbox: {
  37. show: true,
  38. feature: {
  39. // dataView: { show: true, readOnly: false },
  40. // magicType: { show: true, type: ["line", "bar"] },
  41. // restore: { show: true },
  42. saveAsImage: { show: true, color: 'black',title:'',name:'图表下载' },
  43. },
  44. iconStyle: {
  45. borderColor: '#666',
  46. },
  47. right: '10px',
  48. },
  49. // 图列组件
  50. legend: {
  51. itemHeight: 10, //改变圆圈大小
  52. itemWidth: 26, //改变圆圈大小
  53. itemGap: 30,
  54. textStyle: {
  55. color: 'black',
  56. },
  57. bottom: '0',
  58. },
  59. grid: {
  60. left: '3%',
  61. right: '4%',
  62. bottom: '5%',
  63. containLabel: true,
  64. },
  65. xAxis: {
  66. type: 'category',
  67. boundaryGap: true,
  68. data: props.echartsData.listDate.map((val) => {
  69. return val.split(':')[0]
  70. }),
  71. axisTick: {
  72. show: false, //去除刻度线
  73. },
  74. axisLabel: {
  75. color: 'black', // 文本颜色
  76. },
  77. axisLine: {
  78. show: false, // 去除轴线
  79. },
  80. },
  81. yAxis: {
  82. // name: 'kv',
  83. nameTextStyle: {
  84. color: 'black',
  85. fontSize: 10,
  86. },
  87. type: 'value',
  88. axisTick: {
  89. show: true, //去除刻度线
  90. },
  91. axisLabel: {
  92. color: 'black', // 文本颜色
  93. },
  94. axisLine: {
  95. show: true, // 去除轴线
  96. lineStyle: {
  97. color: 'black',
  98. },
  99. },
  100. splitNumber: 5,
  101. splitLine: {
  102. show: true,
  103. lineStyle: {
  104. color: '#9d9d9d',
  105. },
  106. },
  107. },
  108. series: [
  109. {
  110. name: '电量(kWh)',
  111. type: 'line',
  112. smooth: false,
  113. data: props.echartsData.list,
  114. symbolSize: 6,
  115. markPoint: {
  116. data: [
  117. { type: 'max', name: 'Max' },
  118. { type: 'min', name: 'Min' },
  119. ],
  120. },
  121. },
  122. ],
  123. })
  124. window.onresize = function () {
  125. // 自适应大小
  126. myChart.resize()
  127. }
  128. }
  129. onMounted(() => {
  130. // alert(1)
  131. getData()
  132. echarts2()
  133. })
  134. const writeValue = (val) => {
  135. val
  136. echarts2()
  137. getData()
  138. }
  139. //监听变化
  140. watch(
  141. () => props.echartsData,
  142. (newVal, oldVal, clear) => {
  143. // 执行异步任务,并得到关闭异步任务的 id
  144. // alert(1)
  145. console.log(newVal)
  146. let id = writeValue(newVal, oldVal)
  147. // 如果 watch 监听被重复执行了,则会先清除上次未完成的异步任务
  148. clear(() => clearTimeout(id))
  149. },
  150. { lazy: true }
  151. )
  152. return {
  153. total,
  154. num,
  155. echarts,
  156. }
  157. },
  158. })
  159. </script>
  160. <style lang="scss" scoped>
  161. .homeBoxCard {
  162. // margin-bottom: 24px;
  163. :deep(.el-card__header) {
  164. padding-left: 12px;
  165. padding-right: 12px;
  166. }
  167. :deep(.el-card__body) {
  168. padding: 12px;
  169. font-size: 14px;
  170. line-height: 1.5715;
  171. }
  172. :deep(.el-divider) {
  173. margin: 8px 0;
  174. }
  175. .num {
  176. font-size: 30px;
  177. color: #515a6e;
  178. }
  179. }
  180. </style>