pycharm——树状图

复制代码
from pyecharts import options as opts
from pyecharts.charts import Tree


data = [
    {
        "children": [
            {"name": "计算机"},
            {
                "children": [{"children": [{"name": "主机"}], "name": "硬盘"}, {"name": "鼠标和键盘"}],
                "name": "硬件",
            },
            {
                "children": [
                    {"children": [{"name": "操作系统"}, {"name": "数据结构"}], "name": "组成原理"},
                    {"name": "基础"},
                ],
                "name": "软件",
            },
        ],
        "name": "数学",
    }
]
c = (
    Tree()
    .add("", data)
    .set_global_opts(title_opts=opts.TitleOpts(title="Tree-基本示例"))
    .render("tree_base.html")
)
复制代码
import json

from pyecharts import options as opts
from pyecharts.charts import Tree

with open("flare.json", "r", encoding="utf-8") as f:
    j = json.load(f)
c = (
    Tree()
    .add("", [j], collapse_interval=2, layout="radial")
    .set_global_opts(title_opts=opts.TitleOpts(title="Tree-Layout"))
    .render("tree_layout.html")
)

flare.json文件

复制代码
 {
    "name": "My Library",
    "children": [
        {
            "name": "Book",
            "children": [
                {"name": "Title", "value": "The Great Gatsby"},
                {"name": "Author", "value": "F. Scott Fitzgerald"},
                {"name": "Publication Date", "value": "1925-04-10"}
            ]
        },
        {
            "name": "Library",
            "children": [
                {"name": "Name", "value": "Central Library"},
                {"name": "Location", "value": "New York"}
            ]
        },
        {
            "name": "Characters",
            "children": [
                {"name": "Jay Gatsby", "value": "Wealthy Gambler"},
                {"name": "Nick Carraway", "value": "Narrator"},
                {"name": "Daisy Buchanan", "value": "Socialite"}
            ]
        },
        {
          "name": "competer",
          "children": [
            {"name": "数据结构","value": "50"},
            {"name": "数据库原理","value": "60"},
            {"name": "计算机组成网络","value": "40"}
          ]
         }
    ]
}
相关推荐
会编程的吕洞宾8 分钟前
DeepAgents In Action学习(Third)
python·学习·django
'20612 分钟前
**写了个自动整理下载视频的脚本:按片名归档、自动重命名、生成目录索引
开发语言·python·ffmpeg·音视频·cctv
码云数智-园园22 分钟前
Python如何将律师的Excel噩梦变成自动化系统
python·自动化·excel
belldeep30 分钟前
python:Selenium 4.47 编码新的写法
python·selenium
卷无止境30 分钟前
除了开发api,FastAPI其实也可以配合jinja2模板写页面
后端·python·fastapi
OPEN-F34 分钟前
Python进阶教程:项目工程化与虚拟环境
开发语言·python
OPEN-F1 小时前
Python进阶教程:自动化办公实战
python·c#·自动化
躺柒1 小时前
读数据可视化12可视化设计原则
信息可视化·数据分析·可视化·数据可视化·大数据分析
minglie11 小时前
python串口的stream数据mock
python
晚风醉蝶1 小时前
1-16-计数排序-CountingSort
python·算法·排序算法