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"}
          ]
         }
    ]
}
相关推荐
资深流水灯工程师1 分钟前
PySide6 QMainWindow与QWidget秒解
开发语言·python
popcorn_min6 分钟前
California Housing 可复现回归实验:随机森林预测加州房价
python
吴佳浩 Alben8 分钟前
pytorch 你不学?_EP01_环境准备与安装验证
人工智能·pytorch·python
XiaoZhangGOGOGO9 分钟前
新的文本编辑方式
python
留白_19 分钟前
pandas练习题
python·数据分析·pandas
码界索隆27 分钟前
Python转Java系列:面向对象基础
java·开发语言·python
逻辑星辰31 分钟前
x-ds-pow-response逆向分析
开发语言·人工智能·python·深度学习·算法
c_lb728844 分钟前
涨跌停与流动性变差还要不要挂单:quote 涨跌停字段与熔断思路
python·区块链
非生而知之者1 小时前
基于灰狼算法优化的电量预测
python·算法·群体智能算法·电力预测