echarts 树图滚轮放大缩小文字
放大缩小代码
-
使用
getZr()
注册和取消mousewheel
事件 -
字体大小设置放在
textStyle
里面
this.myChart.getZr().off("mousewheel")
this.myChart.getZr().on("mousewheel", (param) => {
let currentOption = this.myChart.getOption();
if (currentOption.series[0]) {
let zoom = currentOption.series[0].zoom;
currentOption.textStyle.fontSize = 10 * zoom
currentOption.series[0].label.width = 150 * zoom
option && this.myChart.setOption(currentOption);
}
});
整体方法代码
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],
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 currentOption = this.myChart.getOption();
if (currentOption.series[0]) {
let zoom = currentOption.series[0].zoom;
currentOption.textStyle.fontSize = 10 * zoom
currentOption.series[0].label.width = 150 * zoom
option && this.myChart.setOption(currentOption);
}
});
},
- 传送门:
分类:
第三方插件库 / echarts
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)