StoreOrderChart.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <template>
  2. <div :class="className" id="echart-customer1" :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. import { getStoreOrderData } from "@/api/index";
  9. const animationDuration = 6000
  10. export default {
  11. props: {
  12. className: {
  13. type: String,
  14. default: 'chart1'
  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. dates:[],
  29. orderCount:[],
  30. payPrice:[]
  31. }
  32. },
  33. mounted() {
  34. this.getStoreOrderData()
  35. this.__resizeHandler = debounce(() => {
  36. if (this.chart) {
  37. this.chart.resize()
  38. }
  39. }, 100)
  40. window.addEventListener('resize', this.__resizeHandler)
  41. },
  42. beforeDestroy() {
  43. if (!this.chart) {
  44. return
  45. }
  46. window.removeEventListener('resize', this.__resizeHandler)
  47. this.chart.dispose()
  48. this.chart = null
  49. },
  50. methods: {
  51. getStoreOrderData(){
  52. var that=this;
  53. getStoreOrderData().then((response) => {
  54. this.dates=response.dates;
  55. this.orderCount=response.orderCount;
  56. this.payPrice=response.payPrice;
  57. setTimeout(() => {
  58. that.initEchart();
  59. }, 500);
  60. });
  61. },
  62. initEchart(){
  63. var option = {
  64. tooltip: {
  65. trigger: 'axis',
  66. axisPointer: { // 坐标轴指示器,坐标轴触发有效
  67. type: 'shadow' // 默认为直线,可选为:'line' | 'shadow'
  68. }
  69. },
  70. legend: {
  71. data: ['订单数', '订单金额']
  72. },
  73. grid: {
  74. left: '3%',
  75. right: '4%',
  76. bottom: '3%',
  77. containLabel: true
  78. },
  79. xAxis: [
  80. {
  81. type: 'category',
  82. data: this.dates
  83. }
  84. ],
  85. yAxis: [
  86. {
  87. type: 'value',
  88. axisLabel:{
  89. formatter:'{value}'
  90. }
  91. }
  92. ],
  93. series: [
  94. {
  95. name: '订单数',
  96. type: 'line',
  97. emphasis: {
  98. focus: 'series'
  99. },
  100. data: this.orderCount
  101. },
  102. {
  103. name: '订单金额',
  104. type: 'line',
  105. emphasis: {
  106. focus: 'series'
  107. },
  108. data: this.payPrice
  109. }
  110. ]
  111. };
  112. this.chart=echarts.init(document.getElementById("echart-customer1"));
  113. this.chart.setOption(option,true);
  114. },
  115. }
  116. }
  117. </script>