efffdade5ad8033f5617a1ef60c1634714b9ebb5.svn-base 2.2 KB

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