nianlingzhanbi.vue 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. top: 20,
  34. },
  35. color:'rgba(9, 101, 98, 1)',
  36. grid: {
  37. left: '3%',
  38. right: '4%',
  39. bottom: '34%',
  40. containLabel: true
  41. },
  42. xAxis: {
  43. type: 'value'
  44. },
  45. yAxis: {
  46. type: 'category',
  47. data: ['41岁及以上', '36-40岁', '31-35岁', '25-30岁', '24岁及以下']
  48. },
  49. series: [
  50. {
  51. name: '人数',
  52. type: 'bar',
  53. stack: 'total',
  54. label: {
  55. show: true
  56. },
  57. emphasis: {
  58. focus: 'series'
  59. },
  60. data: [320, 302, 301, 334, 390, 330, 320]
  61. },
  62. ]
  63. };
  64. myChart.setOption(option);
  65. window.addEventListener("resize", function () {
  66. myChart.resize();
  67. });
  68. this.$on("hook:destroyed", () => {
  69. window.removeEventListener("resize", function () {
  70. chart.resize();
  71. });
  72. });
  73. return option;
  74. },
  75. },
  76. }
  77. </script>
  78. <style>
  79. .chart1 {
  80. width: 100%;
  81. height: 135%;
  82. display: block;
  83. }
  84. </style>