本文主要是介绍echarts 树图滚轮放大缩小文字,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
放大缩小代码
- 使用
getZr()
注册和取消mousewheel
事件
this.myChart.getZr().off("mousewheel")
this.myChart.getZr().on("mousewheel", (param) => {
let option2 = this.myChart.getOption();
if (option2.series[0]) {
let zoom = option2.series[0].zoom;
option2.textStyle.fontSize = 10 * zoom
option2.series[0].label.width = 150 * zoom
option && this.myChart.setOption(option2);
}
});
整体方法代码
initTree() {
const echartDom = this.$refs.myEchartsRef;
this.myChart = this.$echarts.init(echartDom);
this.myChart.clear()
const option = {
color: "#ff0000",
textStyle: {
fontSize: 10
},
series: [
{
type: "tree",
orient: "LR", //竖向或水平 TB代表竖向 LR代表水平
edgeShape: "polyline", //控制折线的形式
id: 0,
name: "tree1",
data: this.verticalTreeData,
top: 0,
left: "20%",
right: "20%",
bottom: 0,
symbolSize: 7,
edgeForkPosition: "63%",
initialTreeDepth: 3,
position: "left",
roam: true,
lineStyle: {
width: 1,
color: "#3a74ca",
},
scaleLimit: {
min: 1,
max: 5
},
label: {
color: "#ffffff",
align: "center",
borderRadius: 5,
width: 150,
padding: [5, 0, 0, 0],
fontSize: 12,
backgroundColor: "#2a61b3",
rich: {
oneBox: {
// fontSize: 12,
borderRadius: 5,
fontWeight: "bold",
},
twoBox: {
// fontSize: 12,
borderRadius: 5,
fontWeight: "bold",
},
threeBox: {
// fontSize: 12,
borderRadius: 5,
fontWeight: "bold",
},
bottomBox: {
// fontSize: 12,
color: "#9eb5d8",
padding: 2,
borderRadius: [0, 0, 5, 5],
},
},
formatter: function (param) {
const { data } = param;
let res = "";
switch (data.state) {
case 1:
res += `{oneBox|${data.equipmentName + "\n"}} {bottomBox| ${data.description
}} `;
break;
case 2:
res += `{twoBox|${data.equipmentName + "\n"}} {bottomBox| ${data.description
}} `;
break;
case 3:
res += `{threeBox|${data.equipmentName + "\n"
}} {bottomBox| ${data.description}} `;
break;
default:
res += `{threeBox|${data.equipmentName + "\n"
}} {bottomBox| ${data.description}} `;
break;
}
return res;
},
},
leaves: {
label: {
position: "right",
verticalAlign: "middle",
// fontSize: 10,
// lineHeight: 40,
align: "center",
},
},
expandAndCollapse: false,
animationDuration: 550,
animationDurationUpdate: 750,
},
],
};
this.myChart.resize();
option && this.myChart.setOption(option, true);
this.myChart.getZr().off("mousewheel")
this.myChart.getZr().on("mousewheel", (param) => {
let option2 = this.myChart.getOption();
if (option2.series[0]) {
let zoom = option2.series[0].zoom;
option2.textStyle.fontSize = 10 * zoom
option2.series[0].label.width = 150 * zoom
option && this.myChart.setOption(option2);
}
});
},
这篇关于echarts 树图滚轮放大缩小文字的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!