YZProjectCloud/yanzhu-bigscreen/src/components/MyChart.vue

62 lines
1.3 KiB
Vue
Raw Normal View History

2024-12-12 00:29:01 +08:00
<template>
2025-05-14 23:49:00 +08:00
<div :id="id" :class="className" :style="{ height, width }"></div>
2024-12-12 00:29:01 +08:00
</template>
<script>
export default {
props: {
2025-05-14 23:49:00 +08:00
id: {
type: String,
default: 'barChart1',
},
className: {
type: String,
default: '',
},
width: {
type: String,
default: '400px',
},
height: {
type: String,
default: '400px',
},
render: {
type: Function,
},
2024-12-12 00:29:01 +08:00
},
2025-05-14 23:49:00 +08:00
data() {
return {
chart: null,
}
2024-12-12 00:29:01 +08:00
},
2025-05-14 23:49:00 +08:00
mounted() {
this.chart = window.echarts.init(document.getElementById(this.id))
setTimeout(() => {
this.setOption({})
}, 400)
// 大小自适应
window.addEventListener('resize', () => {
this.chart.resize()
})
2024-12-12 00:29:01 +08:00
},
2025-05-14 23:49:00 +08:00
methods: {
reLoad() {
let opt = {}
if (this.render) {
opt = this.render(opt)
}
this.chart.setOption(opt, true)
},
setOption(opt) {
if (this.render) {
opt = this.render(opt, this.chart)
}
this.chart.setOption(opt)
},
2024-12-12 00:29:01 +08:00
},
}
</script>
<style>
</style>