minsutongji.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <template>
  2. <view>
  3. <div class="chart1" ref="chart"></div>
  4. </view>
  5. </template>
  6. <script>
  7. import echarts from "echarts";
  8. export default {
  9. props: {
  10. xianmin:{
  11. type: Array,
  12. // 定义是否必须传
  13. required: false,
  14. // 定义默认值
  15. default: []
  16. },
  17. hotelnum:{
  18. type: Array,
  19. // 定义是否必须传
  20. required: false,
  21. // 定义默认值
  22. default: []
  23. },
  24. },
  25. mounted() {
  26. this.getEchartData()
  27. },
  28. watch:{
  29. hotelnum: {
  30. immediate: true,
  31. handler(value) {
  32. this.hotelnum = value
  33. this.getEchartData()
  34. }
  35. },
  36. },
  37. data() {
  38. return {
  39. }
  40. },
  41. methods: {
  42. // 折线图
  43. getEchartData() {
  44. const chart = this.$refs.chart;
  45. var option = null;
  46. const myChart = this.$echarts.init(chart);
  47. option = {
  48. legend: {},
  49. color:'rgba(9, 101, 98, 1)',
  50. grid: {
  51. left: '3%',
  52. right: '4%',
  53. bottom: '34%',
  54. containLabel: true
  55. },
  56. xAxis: {
  57. type: 'value'
  58. },
  59. yAxis: {
  60. type: 'category',
  61. data: this.xianmin
  62. },
  63. series: [
  64. {
  65. name: '数量',
  66. type: 'bar',
  67. stack: 'total',
  68. label: {
  69. show: true
  70. },
  71. emphasis: {
  72. focus: 'series'
  73. },
  74. data: this.hotelnum
  75. },
  76. ]
  77. };
  78. myChart.setOption(option);
  79. window.addEventListener("resize", function () {
  80. myChart.resize();
  81. });
  82. this.$on("hook:destroyed", () => {
  83. window.removeEventListener("resize", function () {
  84. chart.resize();
  85. });
  86. });
  87. return option;
  88. },
  89. },
  90. }
  91. </script>
  92. <style>
  93. .chart1 {
  94. width: 100%;
  95. height: 115%;
  96. display: block;
  97. }
  98. </style>