minsutongji.vue 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. // beforeFan:{
  11. // type: Array,
  12. // // 定义是否必须传
  13. // required: false,
  14. // // 定义默认值
  15. // default: []
  16. // },
  17. },
  18. mounted() {
  19. this.getEchartData()
  20. },
  21. data() {
  22. return {
  23. }
  24. },
  25. methods: {
  26. // 折线图
  27. getEchartData() {
  28. const chart = this.$refs.chart;
  29. var option = null;
  30. const myChart = this.$echarts.init(chart);
  31. option = {
  32. legend: {},
  33. color:'rgb(128, 128, 255)',
  34. grid: {
  35. left: '3%',
  36. right: '4%',
  37. bottom: '34%',
  38. containLabel: true
  39. },
  40. xAxis: {
  41. type: 'value'
  42. },
  43. yAxis: {
  44. type: 'category',
  45. data: ['双溪镇', '中源乡', '宝峰镇', '三爪仑乡', '靖安县']
  46. },
  47. series: [
  48. {
  49. name: '数量',
  50. type: 'bar',
  51. stack: 'total',
  52. label: {
  53. show: true
  54. },
  55. emphasis: {
  56. focus: 'series'
  57. },
  58. data: [320, 302, 301, 334, 390, 330, 320]
  59. },
  60. ]
  61. };
  62. myChart.setOption(option);
  63. window.addEventListener("resize", function () {
  64. myChart.resize();
  65. });
  66. this.$on("hook:destroyed", () => {
  67. window.removeEventListener("resize", function () {
  68. chart.resize();
  69. });
  70. });
  71. return option;
  72. },
  73. },
  74. }
  75. </script>
  76. <style>
  77. .chart1 {
  78. width: 100%;
  79. height: 115%;
  80. display: block;
  81. }
  82. </style>