fangwenliang.vue 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. xAxis: {
  36. type: 'category',
  37. data: ['05-01', '05-02', '05-03', '05-04', '05-05']
  38. },
  39. yAxis: {
  40. type: 'value'
  41. },
  42. series: [
  43. {
  44. name: '访问量',
  45. data: [150, 230, 224, 218, 135, 147, 260],
  46. type: 'line'
  47. }
  48. ]
  49. };
  50. myChart.setOption(option);
  51. window.addEventListener("resize", function () {
  52. myChart.resize();
  53. });
  54. this.$on("hook:destroyed", () => {
  55. window.removeEventListener("resize", function () {
  56. chart.resize();
  57. });
  58. });
  59. return option;
  60. },
  61. },
  62. }
  63. </script>
  64. <style>
  65. .chart1 {
  66. width: 100%;
  67. height: 115%;
  68. display: block;
  69. }
  70. </style>