2023-06-12 20:34:21 +08:00
|
|
|
<template>
|
2023-06-21 18:31:31 +08:00
|
|
|
<div class="custom-chart" ref="containerRef" :style="{ height: height + 'px' }"></div>
|
2023-06-12 20:34:21 +08:00
|
|
|
</template>
|
|
|
|
|
<script>
|
2023-06-21 18:31:31 +08:00
|
|
|
import * as echarts from 'echarts'
|
2023-06-12 20:34:21 +08:00
|
|
|
export default {
|
2023-06-21 18:31:31 +08:00
|
|
|
props: {
|
|
|
|
|
option: {
|
|
|
|
|
type: Object,
|
|
|
|
|
default: () => ({})
|
2023-06-12 20:34:21 +08:00
|
|
|
},
|
2023-06-21 18:31:31 +08:00
|
|
|
height: {
|
|
|
|
|
type: Number,
|
|
|
|
|
default: 0
|
|
|
|
|
}
|
|
|
|
|
},
|
2023-06-12 20:34:21 +08:00
|
|
|
data() {
|
|
|
|
|
return {}
|
|
|
|
|
},
|
|
|
|
|
mounted() {
|
|
|
|
|
this.chart = echarts.init(this.$refs.containerRef)
|
|
|
|
|
this.chart.setOption(this.option)
|
2023-06-21 18:31:31 +08:00
|
|
|
},
|
|
|
|
|
watch : {
|
|
|
|
|
option: {
|
|
|
|
|
handler() {
|
2023-06-25 14:18:45 +08:00
|
|
|
if(this.chart) {
|
|
|
|
|
this.chart.clear()
|
|
|
|
|
this.chart.setOption(this.option)
|
|
|
|
|
}
|
2023-06-21 18:31:31 +08:00
|
|
|
},
|
|
|
|
|
deep: true
|
|
|
|
|
},
|
|
|
|
|
height() {
|
|
|
|
|
this.$nextTick(() => {
|
|
|
|
|
this.chart && this.chart.resize()
|
|
|
|
|
})
|
|
|
|
|
}
|
2023-06-12 20:34:21 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
<style lang="less" scoped>
|
|
|
|
|
.custom-chart {
|
2023-06-21 18:31:31 +08:00
|
|
|
height: 100%;
|
2023-06-12 20:34:21 +08:00
|
|
|
}
|
|
|
|
|
</style>
|