adStruct.vue 977 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <template>
  2. <div style="height: 500px;" ref="lineRef"></div>
  3. </template>
  4. <script lang="ts" setup>
  5. import { ref,onMounted, onBeforeUnmount } from 'vue'
  6. import * as echarts from 'echarts'
  7. defineOptions({
  8. name: "AdStructChart"
  9. })
  10. let chartObj:any
  11. const lineRef = ref()
  12. const resizeChart = () => { chartObj.resize() }
  13. const addResize = () => { window.addEventListener('resize', resizeChart) }
  14. const removeResize = () => { window.removeEventListener('resize', resizeChart) }
  15. onMounted(() => {
  16. initLine()
  17. addResize()
  18. });
  19. onBeforeUnmount(() => {
  20. if(chartObj) {
  21. chartObj.dispose()
  22. chartObj = null
  23. }
  24. removeResize()
  25. })
  26. const initLine = () => {
  27. chartObj = echarts.init(lineRef.value)
  28. const option = {
  29. xAxis: {
  30. data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
  31. },
  32. yAxis: {},
  33. series: [
  34. {
  35. type: 'bar',
  36. data: [23, 24, 18, 25, 27, 28, 25]
  37. }
  38. ]
  39. }
  40. chartObj.setOption(option)
  41. }
  42. defineExpose({resizeChart})
  43. </script>
  44. <style scoped>
  45. </style>