vue中,
onMounted(() => {
try {
let $echarts = inject("echarts");
let myChart = $echarts.init(document.getElementById("treeChart"));
let option = getoption(mydata)
myChart.setOption(option);
// myChart.on("click", treeNodeclick);
myChart.on("click", function (param) {
console.log("param:",param)
let container = document.getElementById("treeChart")
// 自适应高度
if (param.componentType === "series") {
let elesArr = Array.from(
new Set(myChart._chartsViews[0]._data._graphicEls)
);
let height = 1080;//默认高度
let currentHeight = 35 * (elesArr.length - 1) || 100; //动态高度
let newHeight = Math.max(currentHeight, height);
container.style.height = newHeight + "px";
myChart.resize();
}
}
);
}
catch (error) {
console.error(error);
}
}
至于滚动条
<div style="overflow:auto; height: calc(80vh); ">
<div class="chart" id="treeChart">Tree</div>
</div>