from pyecharts import options as opts
from pyecharts.charts import Tree
# 定义树形结构
tree_data = [
{
"name": "A",
"children": [
{"name": "B", "children": [{"name": "E"}, {"name": "F"}]},
{"name": "C", "children": [{"name": "G"}, {"name": "H"}]},
],
},
{"name": "D", "children": [{"name": "I"}, {"name": "J"}]},
]
# 创建树形图
tree = Tree()
tree.add("", tree_data)
# 设置树形图配置项
tree.set_global_opts(title_opts=opts.TitleOpts(title="树形图"))
# 渲染树形图
tree.render("tree.html")