eChartView.vue 726 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <template>
  2. <div class="chart" id="charts_canvas" ref="chartRef"></div>
  3. </template>
  4. <script>
  5. import * as echarts from 'echarts';
  6. export default {
  7. props: {
  8. data: {
  9. type: Object,
  10. default: () => {},
  11. },
  12. },
  13. data() {
  14. return {
  15. chartObj: null,
  16. chartData: null,
  17. };
  18. },
  19. watch: {
  20. data() {
  21. this.getChartData();
  22. },
  23. },
  24. methods: {
  25. getChartData() {
  26. this.chartObj = echarts.init(this.$refs.chartRef);
  27. this.chartObj.setOption(this.data);
  28. window.addEventListener("resize", () => {
  29. this.chartObj.resize();
  30. });
  31. },
  32. },
  33. mounted() {
  34. // this.$nextTick(()=>{
  35. this.getChartData();
  36. // })
  37. },
  38. };
  39. </script>
  40. <style scoped>
  41. .chart {
  42. max-width: 100%;
  43. width: 100%;
  44. height: 100%;
  45. }
  46. </style>