<div id="line" style="width: 1000px;"></div>
export default {
// dom挂载再调用,因为created钩子里面dom还没挂载
mounted() {
this.lineChart()
},
methods:{
lineChart() {
const myChart = echarts.init(document.getElementById('line'));
/*
* ..
*/
//清除画布,这样重新绘制的时候就不会遗留之前的数据
myChart.clear();
// 绘制图表
myChart.setOption(options);
// 这个counst.length是渲染数据的长度
//第一个50是为我给每个柱状图的高度,第二个50是为柱状图x轴内容的高度(大概的)
const autoHeight = this.counst.length * 50 + 50
//以下两个方法改变高度都可以
/**
* myChart.getDom().style.height = autoHeight + "px";
*/
myChart.resize({height: autoHeight})
},
}
}