fangwenliang.vue 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. fangQu:{
  11. type: Array,
  12. // 定义是否必须传
  13. required: false,
  14. // 定义默认值
  15. default: []
  16. },
  17. fangquTime:{
  18. type: Array,
  19. // 定义是否必须传
  20. required: false,
  21. // 定义默认值
  22. default: []
  23. },
  24. },
  25. mounted() {
  26. this.getEchartData()
  27. },
  28. watch:{
  29. fangQu: {
  30. immediate: true,
  31. handler(value) {
  32. this.fangQu = 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. top: 20,
  50. },
  51. xAxis: {
  52. type: 'category',
  53. data: this.fangquTime//['05-01', '05-02', '05-03', '05-04', '05-05']
  54. },
  55. yAxis: {
  56. type: 'value'
  57. },
  58. series: [
  59. {
  60. name: '访问量',
  61. data: this.fangQu,//[150, 230, 224, 218, 135, 147, 260],
  62. type: 'line'
  63. }
  64. ]
  65. };
  66. myChart.setOption(option);
  67. window.addEventListener("resize", function () {
  68. myChart.resize();
  69. });
  70. this.$on("hook:destroyed", () => {
  71. window.removeEventListener("resize", function () {
  72. chart.resize();
  73. });
  74. });
  75. return option;
  76. },
  77. },
  78. }
  79. </script>
  80. <style>
  81. .chart1 {
  82. width: 100%;
  83. height: 115%;
  84. display: block;
  85. }
  86. </style>