<template>
  <div
    ref="chart"
    class="echarts"
  />
</template>

<script setup lang='ts'>
import * as Echarts from 'echarts'
import {
  nextTick, onUnmounted, ref, watch
} from 'vue'

const props = defineProps<{
    option: Echarts.EChartsOption | any
}>()
const chart = ref()
const myChart = ref()

nextTick(() => {
  myChart.value = Echarts.init(chart.value)
})

watch(() => props.option, (v) => {
  nextTick(() => {
    myChart.value.setOption(v)
  })
}, { deep: true, immediate: true })

onUnmounted(() => {
  if (myChart.value) myChart.value.dispose()
})
</script>

<style lang="scss" scoped>
.echarts {
    width: 100%;
    height: 100%;
    min-width: 300px;
    min-height: 300px;
}
</style>