ChartDl.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <template>
  2. <div :id="'chartDl-' + id" style="width: 100%; height: 100%"></div>
  3. </template>
  4. <script>
  5. import { mapState } from 'vuex';
  6. export default {
  7. name: "ChartDl",
  8. props: {
  9. id: {
  10. type: String,
  11. default: () => '0'
  12. }
  13. },
  14. computed: {
  15. ...mapState(['color'])
  16. },
  17. data() {
  18. return {
  19. myChart: null
  20. }
  21. },
  22. watch: {
  23. color(newVal) {
  24. if(newVal) {
  25. this.myChart.clear();
  26. this.init()
  27. }
  28. }
  29. },
  30. methods: {
  31. init() {
  32. let dataAxis = ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月', '测试月'];
  33. let start = dataAxis.length - 12;
  34. let end = dataAxis.length - 1;
  35. let options = {
  36. tooltip: {
  37. trigger: 'axis',
  38. },
  39. color: [this.color],
  40. dataZoom: [{
  41. type: 'inside',
  42. startValue: start,
  43. endValue: end,
  44. show: false
  45. // zoomOnMouseWheel: false,
  46. // zoomLock: true,
  47. }],
  48. // dataZoom: [
  49. //
  50. // {
  51. // type: 'slider',
  52. // startValue: start,
  53. // endValue:end,
  54. // zoomOnMouseWheel: false,
  55. // zoomLock: true,
  56. // },
  57. // {
  58. // type: 'inside'
  59. // },
  60. // ],
  61. xAxis: [
  62. {
  63. type: 'category',
  64. data: dataAxis,
  65. axisPointer: {
  66. type: 'shadow'
  67. },
  68. axisLine: {
  69. show: false,
  70. lineStyle: {
  71. color: '#6e7079',
  72. }
  73. },
  74. axisTick:{
  75. show:false
  76. },
  77. }
  78. ],
  79. yAxis: [
  80. {
  81. type: 'value',
  82. name: '电量统计情况',
  83. axisLabel: {
  84. formatter: '{value} KW·h'
  85. },
  86. axisLine: {
  87. show: false,
  88. lineStyle: {
  89. color: '#6e7079',
  90. }
  91. },
  92. axisTick:{
  93. show:false
  94. },
  95. }
  96. ],
  97. series: [
  98. {
  99. name: '电量',
  100. type: 'line',
  101. // stack: 'Total',
  102. smooth: true,
  103. areaStyle: {},
  104. emphasis: {
  105. focus: 'series'
  106. },
  107. itemStyle : {
  108. color: this.color,
  109. borderColor: this.color,
  110. normal: {
  111. label : {
  112. show: true,
  113. textStyle: {
  114. fontSize: 14
  115. }
  116. }
  117. }
  118. },
  119. data: [120, 132, 101, 134, 90, 230, 210, 210, 245, 203, 124, 214, 210]
  120. }
  121. ]
  122. }
  123. this.myChart.setOption(options)
  124. }
  125. },
  126. mounted() {
  127. this.myChart = this.$echarts.init(document.getElementById('chartDl-' + this.id));
  128. this.init()
  129. }
  130. }
  131. </script>
  132. <style scoped>
  133. </style>