|
|
@ -1,5 +1,5 @@
|
|
|
|
<template>
|
|
|
|
<template>
|
|
|
|
<div style="width: 100%;height: 100%"/>
|
|
|
|
<div style="width: 100%;height: 100%" ref="chart" @resize="resize"/>
|
|
|
|
</template>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
<script>
|
|
|
@ -10,9 +10,20 @@ export default {
|
|
|
|
data() {
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
chart: null,
|
|
|
|
chart: null,
|
|
|
|
|
|
|
|
resizeTime:true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
mounted() {
|
|
|
|
|
|
|
|
this.$nextTick(() => {
|
|
|
|
|
|
|
|
const resizeObserver = new ResizeObserver(entries => {
|
|
|
|
|
|
|
|
for (let entry of entries) {
|
|
|
|
|
|
|
|
this.resize()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
resizeObserver.observe(this.$refs.chart);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
window.addEventListener('resize', this.resize)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
beforeDestroy() {
|
|
|
|
beforeDestroy() {
|
|
|
|
if (!this.chart) {
|
|
|
|
if (!this.chart) {
|
|
|
@ -20,16 +31,29 @@ export default {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.chart.dispose()
|
|
|
|
this.chart.dispose()
|
|
|
|
this.chart = null
|
|
|
|
this.chart = null
|
|
|
|
|
|
|
|
window.removeEventListener('resize', this.resize)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
methods: {
|
|
|
|
setData(option) {
|
|
|
|
setData(option) {
|
|
|
|
this.initChart(option)
|
|
|
|
this.initChart(option)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
initChart(option) {
|
|
|
|
initChart(option) {
|
|
|
|
this.chart = echarts.init(this.$el, 'macarons')
|
|
|
|
this.chart = echarts.init(this.$refs.chart, 'macarons')
|
|
|
|
|
|
|
|
|
|
|
|
this.chart.setOption(option)
|
|
|
|
this.chart.setOption(option)
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
resize() {
|
|
|
|
|
|
|
|
if (this.resizeTime) {
|
|
|
|
|
|
|
|
this.resizeTime = false
|
|
|
|
|
|
|
|
if (this.chart) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.chart.resize()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
|
|
this.resizeTime = true
|
|
|
|
|
|
|
|
}, 16)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
</script>
|
|
|
|