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"}
          ]
         }
    ]
}
相关推荐
程序员小远26 分钟前
软件测试之bug分析定位技巧
自动化测试·软件测试·python·测试工具·职场和发展·测试用例·bug
江上清风山间明月1 小时前
Android 系统中进程和线程的区别
android·python·线程·进程
mit6.8241 小时前
[LivePortrait] docs | Gradio用户界面
python
听风吟丶2 小时前
Java 函数式编程深度实战:从 Lambda 到 Stream API 的工程化落地
开发语言·python
饮长安千年月3 小时前
玄机-第八章 内存马分析-java03-fastjson
开发语言·python·安全·web安全·网络安全·应急响应
天天爱吃肉82183 小时前
新能源汽车动力系统在环(HIL)半实物仿真测试台架深度解析
人工智能·python·嵌入式硬件·汽车
卡次卡次13 小时前
注意点:挂载与插硬盘,容器挂载实现持久化存储
python
2401_841495643 小时前
【LeetCode刷题】找到字符串中所有字母异位词
数据结构·python·算法·leetcode·数组·滑动窗口·找到字符串中所有字母异位词
MediaTea3 小时前
Python 第三方库:OpenPyXL(Excel 文件读写与操作)
开发语言·python·excel
自学互联网4 小时前
python爬虫入门案例day05:Pexels
开发语言·爬虫·python