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"}
          ]
         }
    ]
}
相关推荐
larance21 分钟前
jupyter 服务端扩展开发
ide·python·jupyter
.似水29 分钟前
Python Socket
开发语言·python
宁大小白39 分钟前
pythonstudy Day45
开发语言·python·深度学习
AI手记叨叨1 小时前
Python数学:统计运算
python·数学·统计运算·描述统计·概率运算
Brian Xia1 小时前
从0开始手写AI Agent框架:nano-agentscope(一)项目介绍
人工智能·python·ai
电商API&Tina2 小时前
【电商API接口】多电商平台数据API接入方案(附带实例)
运维·开发语言·数据库·chrome·爬虫·python·jenkins
ZPC82102 小时前
FANUC 机器人 PR 寄存器
人工智能·python·算法·机器人
秃了也弱了。2 小时前
python实现语音识别:SpeechRecognition库
python
yaoxin5211232 小时前
278. Java Stream API - 限制与跳过操作全解析
java·开发语言·python
love530love2 小时前
【探讨】“父级/基环境损坏,子环境全部失效”,如何避免 .venv 受父级 Python 损坏影响?
java·开发语言·人工智能·windows·python·编程·ai编程