Rap 原分销系统代码Web
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

108 lines
2.1KB

  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. export default {
  9. props: {
  10. className: {
  11. type: String,
  12. default: 'chart'
  13. },
  14. width: {
  15. type: String,
  16. default: '100%'
  17. },
  18. height: {
  19. type: String,
  20. default: '300px'
  21. }
  22. },
  23. data() {
  24. return {
  25. chart: null
  26. }
  27. },
  28. mounted() {
  29. this.initChart()
  30. this.__resizeHandler = debounce(() => {
  31. if (this.chart) {
  32. this.chart.resize()
  33. }
  34. }, 100)
  35. window.addEventListener('resize', this.__resizeHandler)
  36. },
  37. beforeDestroy() {
  38. if (!this.chart) {
  39. return
  40. }
  41. window.removeEventListener('resize', this.__resizeHandler)
  42. this.chart.dispose()
  43. this.chart = null
  44. },
  45. methods: {
  46. initChart() {
  47. this.chart = echarts.init(this.$el, 'macarons')
  48. const data = [{
  49. name: 'Grandpa',
  50. children: [{
  51. name: 'Uncle Leo',
  52. value: 15,
  53. children: [{
  54. name: 'Cousin Jack',
  55. value: 2
  56. }, {
  57. name: 'Cousin Mary',
  58. value: 5,
  59. children: [{
  60. name: 'Jackson',
  61. value: 2
  62. }]
  63. }, {
  64. name: 'Cousin Ben',
  65. value: 4
  66. }]
  67. }, {
  68. name: 'Father',
  69. value: 10,
  70. children: [{
  71. name: 'Me',
  72. value: 5
  73. }, {
  74. name: 'Brother Peter',
  75. value: 1
  76. }]
  77. }]
  78. }, {
  79. name: 'Nancy',
  80. children: [{
  81. name: 'Uncle Nike',
  82. children: [{
  83. name: 'Cousin Betty',
  84. value: 1
  85. }, {
  86. name: 'Cousin Jenny',
  87. value: 2
  88. }]
  89. }]
  90. }]
  91. this.chart.setOption({
  92. series: {
  93. type: 'sunburst',
  94. data: data,
  95. radius: [0, '90%'],
  96. label: {
  97. rotate: 'radial'
  98. }
  99. }
  100. })
  101. }
  102. }
  103. }
  104. </script>