storeOrderMoney.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <template>
  2. <div ref="chartContainer" style="width: 100%; height: 400px;"></div>
  3. </template>
  4. <script>
  5. import echarts from 'echarts'
  6. import { orderChartData,listAdv, getAdv, delAdv, addAdv, updateAdv, exportAdv } from "@/api/his/index";
  7. export default {
  8. data() {
  9. return {
  10. chart: null,
  11. data: [
  12. ],
  13. };
  14. },
  15. mounted() {
  16. this.chart = echarts.init(this.$refs.chartContainer, 'macarons');
  17. this.chart.on('mouseout', this.hideTooltip);
  18. this.updateChart();
  19. this.getorderChartData();
  20. },
  21. watch: {
  22. data() {
  23. this.updateChart();
  24. },
  25. },
  26. methods: {
  27. getorderChartData(){
  28. orderChartData().then(response => {
  29. this.data = response.data;
  30. });
  31. },
  32. formatter(params) {
  33. const item = params[0];
  34. return `
  35. <div>
  36. <div>日期:${item.axisValue}</div>
  37. <div>收入金额:${item.value}元</div>
  38. <div>订单数量:${item.data.info}</div>
  39. </div>
  40. `;;
  41. },
  42. updateChart() {
  43. const option = {
  44. xAxis: {
  45. type: 'category',
  46. data: this.data.map((item) => item.label),
  47. },
  48. yAxis: {
  49. type: 'value',
  50. },
  51. tooltip: {
  52. trigger: 'axis',
  53. formatter: this.formatter,
  54. axisPointer: {
  55. type: "line",
  56. lineStyle: {
  57. color: "rgba(227, 242, 252, 0.39)",
  58. width: 40,
  59. type: "solid",
  60. },
  61. z: 0, //注意要设置层级,不然会在覆盖在柱子前面,设置为0就在柱子后面显示了。
  62. },
  63. },
  64. series: [
  65. {
  66. name: 'Value',
  67. type: 'bar',
  68. barWidth: '40%',
  69. itemStyle: {
  70. color: '#3399CC',
  71. },
  72. label: {
  73. show: true,
  74. position: 'top',
  75. },
  76. data: this.data.map((item) => ({ value: item.value, info: item.info })),
  77. },
  78. ],
  79. };
  80. this.chart.setOption(option);
  81. },
  82. hideTooltip() {
  83. this.chart.dispatchAction({
  84. type: 'hideTip',
  85. });
  86. },
  87. },
  88. };
  89. </script>