ChartLines.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <template>
  2. <div :id="'chart-lines' + id" style="width: 100%; height: 100%" />
  3. </template>
  4. <script>
  5. let myChart = null
  6. import echarts from 'echarts'
  7. export default {
  8. name: 'ChartLines',
  9. props: {
  10. id: {
  11. type: Number,
  12. default: 0
  13. },
  14. list: {
  15. type: Array,
  16. default: () => []
  17. }
  18. },
  19. watch: {
  20. list: {
  21. handler() {
  22. myChart.clear()
  23. this.init()
  24. },
  25. deep: true
  26. }
  27. },
  28. mounted() {
  29. this.init()
  30. },
  31. methods: {
  32. init() {
  33. myChart = echarts.init(document.getElementById('chart-lines' + this.id))
  34. const time = []
  35. const data = []
  36. if (this.list.length > 0) {
  37. this.list.forEach(item => {
  38. time.push(item.time)
  39. data.push(item.total / 100)
  40. })
  41. }
  42. const options = {
  43. tooltip: {
  44. trigger: 'axis'
  45. },
  46. color: ['#6BBEAE', '#1890FF'],
  47. xAxis: {
  48. type: 'category',
  49. boundaryGap: true,
  50. data: time,
  51. axisLine: {
  52. show: true,
  53. lineStyle: {
  54. color: '#aaa'
  55. }
  56. },
  57. axisLabel: {
  58. color: '#aaa'
  59. }
  60. },
  61. yAxis: [
  62. {
  63. type: 'value',
  64. name: '单位:元',
  65. boundaryGap: [0, '100%'],
  66. axisLine: { // y轴
  67. show: false
  68. },
  69. axisTick: {
  70. show: false
  71. },
  72. splitLine: {
  73. show: false
  74. }
  75. }
  76. ],
  77. series: [
  78. {
  79. name: `总收入`,
  80. type: 'line',
  81. // stack: 'Total',
  82. data: data,
  83. barWidth: 20,
  84. tooltip: {
  85. valueFormatter: function(value) {
  86. return value + ' 元'
  87. }
  88. }
  89. }
  90. ]
  91. }
  92. myChart.setOption(options)
  93. }
  94. }
  95. }
  96. </script>
  97. <style scoped>
  98. </style>