Rap 原分销系统代码Web
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
2.3KB

  1. <template>
  2. <div :class="className" :style="{height:height,width:width}" />
  3. </template>
  4. <script>
  5. import echarts from 'echarts'
  6. require('echarts/theme/macarons') // echarts theme
  7. import { debounce } from '@/utils'
  8. const animationDuration = 6000
  9. export default {
  10. props: {
  11. className: {
  12. type: String,
  13. default: 'chart'
  14. },
  15. width: {
  16. type: String,
  17. default: '100%'
  18. },
  19. height: {
  20. type: String,
  21. default: '300px'
  22. }
  23. },
  24. data() {
  25. return {
  26. chart: null
  27. }
  28. },
  29. mounted() {
  30. this.initChart()
  31. this.__resizeHandler = debounce(() => {
  32. if (this.chart) {
  33. this.chart.resize()
  34. }
  35. }, 100)
  36. window.addEventListener('resize', this.__resizeHandler)
  37. },
  38. beforeDestroy() {
  39. if (!this.chart) {
  40. return
  41. }
  42. window.removeEventListener('resize', this.__resizeHandler)
  43. this.chart.dispose()
  44. this.chart = null
  45. },
  46. methods: {
  47. initChart() {
  48. this.chart = echarts.init(this.$el, 'macarons')
  49. this.chart.setOption({
  50. tooltip: {
  51. trigger: 'axis',
  52. axisPointer: { // 坐标轴指示器,坐标轴触发有效
  53. type: 'shadow' // 默认为直线,可选为:'line' | 'shadow'
  54. }
  55. },
  56. grid: {
  57. top: 10,
  58. left: '2%',
  59. right: '2%',
  60. bottom: '3%',
  61. containLabel: true
  62. },
  63. xAxis: [{
  64. type: 'category',
  65. data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
  66. axisTick: {
  67. alignWithLabel: true
  68. }
  69. }],
  70. yAxis: [{
  71. type: 'value',
  72. axisTick: {
  73. show: false
  74. }
  75. }],
  76. series: [{
  77. name: 'pageA',
  78. type: 'bar',
  79. stack: 'vistors',
  80. barWidth: '60%',
  81. data: [79, 52, 200, 334, 390, 330, 220],
  82. animationDuration
  83. }, {
  84. name: 'pageB',
  85. type: 'bar',
  86. stack: 'vistors',
  87. barWidth: '60%',
  88. data: [80, 52, 200, 334, 390, 330, 220],
  89. animationDuration
  90. }, {
  91. name: 'pageC',
  92. type: 'bar',
  93. stack: 'vistors',
  94. barWidth: '60%',
  95. data: [30, 52, 200, 334, 390, 330, 220],
  96. animationDuration
  97. }]
  98. })
  99. }
  100. }
  101. }
  102. </script>