不设置宽度 只设置高度即可
宽度自适应代码
mounted() {
const chartDomZy = document.getElementById('zyBar')
const chartDomJz = document.getElementById('jzBar')
this.zyChart = echarts.init(chartDomZy)
this.jzChart = echarts.init(chartDomJz)
this.$nextTick(()=>{//页面初始化时放在nextTick中执行一次自适应
this.zyChart.resize()
this.jzChart.resize()
})
window.addEventListener('resize', this.resizeTheChart) //监听屏幕变化时自适应图表
},
computed: {},
watch: {},
methods: {
resizeTheChart() {
if (this.zyChart) {
this.zyChart.resize()
}
if (this.jzChart) {
this.jzChart.resize()
}
},
}