在当我们将浏览器的窗口缩小时,图表也会跟着缩小;但当我们将浏览器窗口还原放大时,发现图表并没有跟着返回原来的大小,会出现压缩的情况。这时我们应该实现自适应。
mounted() {
this.initChart();
let self = this;
window.onresize = function(){
if(self.chart){
self.chart.resize()
}
};
},
methods: {
initChart() {
this.chart = this.$echarts.init(document.getElementById(this.id));
this.chart.setOption({
backgroundColor: this.bgColor,
)}
}
}