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.

102 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 axisData = ['周一', '周二', '周三', '很长很长的周四', '周五', '周六', '周日']
  49. const data = axisData.map(function(item, i) {
  50. return Math.round(Math.random() * 1000 * (i + 1))
  51. })
  52. const links = data.map(function(item, i) {
  53. return {
  54. source: i,
  55. target: i + 1
  56. }
  57. })
  58. links.pop()
  59. this.chart.setOption({
  60. title: {
  61. text: '笛卡尔坐标系上的 Graph'
  62. },
  63. tooltip: {},
  64. xAxis: {
  65. type: 'category',
  66. boundaryGap: false,
  67. data: axisData
  68. },
  69. yAxis: {
  70. type: 'value'
  71. },
  72. series: [
  73. {
  74. type: 'graph',
  75. layout: 'none',
  76. coordinateSystem: 'cartesian2d',
  77. symbolSize: 40,
  78. label: {
  79. normal: {
  80. show: true
  81. }
  82. },
  83. edgeSymbol: ['circle', 'arrow'],
  84. edgeSymbolSize: [4, 10],
  85. data: data,
  86. links: links,
  87. lineStyle: {
  88. normal: {
  89. color: '#2f4554'
  90. }
  91. }
  92. }
  93. ]
  94. })
  95. }
  96. }
  97. }
  98. </script>