ChartSewageLine.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <template>
  2. <div :id="'chart-sewage-line-' + lineConfig.id" style="width: 100%; height: 100%"></div>
  3. </template>
  4. <script>
  5. import { mapState } from 'vuex'
  6. export default {
  7. name: "ChartSewageLine",
  8. computed: {
  9. ...mapState(['color'])
  10. },
  11. props: {
  12. lineConfig: {
  13. type: Object,
  14. default: function () {
  15. return {
  16. id: 0,
  17. time: [],
  18. data: [],
  19. name: '默认',
  20. unit: '%'
  21. }
  22. }
  23. }
  24. },
  25. watch: {
  26. color(newVal) {
  27. if(newVal) {
  28. this.myChart.clear();
  29. this.init()
  30. }
  31. }
  32. },
  33. data() {
  34. return {
  35. myChart: null
  36. }
  37. },
  38. methods: {
  39. init() {
  40. // 时间
  41. let dataAxis = this.lineConfig.time;
  42. let start = dataAxis.length - 12;
  43. let end = dataAxis.length - 1;
  44. // 数据
  45. let data = this.lineConfig.data;
  46. // 单位
  47. let unit = this.lineConfig.unit;
  48. // 名称
  49. let name = this.lineConfig.name;
  50. let options = {
  51. title: {
  52. text: name,
  53. top: "5%",
  54. left: '2%',
  55. textStyle: {
  56. color: this.color,
  57. fontSize: 16,
  58. fontWeight: 300,
  59. },
  60. padding: 5,
  61. },
  62. tooltip: {
  63. trigger: 'axis',
  64. },
  65. color: [this.color],
  66. dataZoom: [{
  67. type: 'inside',
  68. startValue: start,
  69. endValue: end,
  70. show: false
  71. // zoomOnMouseWheel: false,
  72. // zoomLock: true,
  73. }],
  74. // dataZoom: [
  75. //
  76. // {
  77. // type: 'slider',
  78. // startValue: start,
  79. // endValue:end,
  80. // zoomOnMouseWheel: false,
  81. // zoomLock: true,
  82. // },
  83. // {
  84. // type: 'inside'
  85. // },
  86. // ],
  87. xAxis: [
  88. {
  89. type: 'category',
  90. data: dataAxis,
  91. axisPointer: {
  92. type: 'shadow'
  93. },
  94. axisLine: {
  95. show: false,
  96. lineStyle: {
  97. color: '#6e7079',
  98. }
  99. },
  100. axisTick:{
  101. show:false
  102. },
  103. }
  104. ],
  105. yAxis: [
  106. {
  107. type: 'value',
  108. name: '近7天统计',
  109. axisLabel: {
  110. formatter: `{value}${unit}`
  111. },
  112. axisLine: {
  113. show: false,
  114. lineStyle: {
  115. color: '#6e7079',
  116. }
  117. },
  118. axisTick:{
  119. show:false
  120. },
  121. }
  122. ],
  123. series: [
  124. {
  125. name: name,
  126. type: 'line',
  127. // stack: 'Total',
  128. smooth: true,
  129. areaStyle: {},
  130. emphasis: {
  131. focus: 'series'
  132. },
  133. itemStyle : {
  134. color: this.color,
  135. borderColor: this.color,
  136. normal: {
  137. label : {
  138. show: true,
  139. textStyle: {
  140. fontSize: 14
  141. }
  142. }
  143. }
  144. },
  145. data: data
  146. }
  147. ]
  148. }
  149. this.myChart.setOption(options)
  150. }
  151. },
  152. mounted() {
  153. this.myChart = this.$echarts.init(document.getElementById('chart-sewage-line-' + this.lineConfig.id));
  154. this.init()
  155. }
  156. }
  157. </script>
  158. <style scoped>
  159. </style>