Rap 原分销系统代码Web
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

136 satır
2.6KB

  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 resize from './mixins/resize'
  8. export default {
  9. mixins: [resize],
  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: '350px'
  22. },
  23. autoResize: {
  24. type: Boolean,
  25. default: true
  26. },
  27. chartData: {
  28. type: Object,
  29. required: true
  30. }
  31. },
  32. data() {
  33. return {
  34. chart: null
  35. }
  36. },
  37. watch: {
  38. chartData: {
  39. deep: true,
  40. handler(val) {
  41. this.setOptions(val)
  42. }
  43. }
  44. },
  45. mounted() {
  46. this.$nextTick(() => {
  47. this.initChart()
  48. })
  49. },
  50. beforeDestroy() {
  51. if (!this.chart) {
  52. return
  53. }
  54. this.chart.dispose()
  55. this.chart = null
  56. },
  57. methods: {
  58. initChart() {
  59. this.chart = echarts.init(this.$el, 'macarons')
  60. this.setOptions(this.chartData)
  61. },
  62. setOptions({ expectedData, actualData } = {}) {
  63. this.chart.setOption({
  64. xAxis: {
  65. data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
  66. boundaryGap: false,
  67. axisTick: {
  68. show: false
  69. }
  70. },
  71. grid: {
  72. left: 10,
  73. right: 10,
  74. bottom: 20,
  75. top: 30,
  76. containLabel: true
  77. },
  78. tooltip: {
  79. trigger: 'axis',
  80. axisPointer: {
  81. type: 'cross'
  82. },
  83. padding: [5, 10]
  84. },
  85. yAxis: {
  86. axisTick: {
  87. show: false
  88. }
  89. },
  90. legend: {
  91. data: ['expected', 'actual']
  92. },
  93. series: [{
  94. name: 'expected', itemStyle: {
  95. normal: {
  96. color: '#FF005A',
  97. lineStyle: {
  98. color: '#FF005A',
  99. width: 2
  100. }
  101. }
  102. },
  103. smooth: true,
  104. type: 'line',
  105. data: expectedData,
  106. animationDuration: 2800,
  107. animationEasing: 'cubicInOut'
  108. },
  109. {
  110. name: 'actual',
  111. smooth: true,
  112. type: 'line',
  113. itemStyle: {
  114. normal: {
  115. color: '#3888fa',
  116. lineStyle: {
  117. color: '#3888fa',
  118. width: 2
  119. },
  120. areaStyle: {
  121. color: '#f3f8ff'
  122. }
  123. }
  124. },
  125. data: actualData,
  126. animationDuration: 2800,
  127. animationEasing: 'quadraticOut'
  128. }]
  129. })
  130. }
  131. }
  132. }
  133. </script>