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"}
          ]
         }
    ]
}
相关推荐
用户27784491049935 小时前
借助DeepSeek智能生成测试用例:从提示词到Excel表格的全流程实践
人工智能·python
JavaEdge在掘金7 小时前
ssl.SSLCertVerificationError报错解决方案
python
我不会编程5558 小时前
Python Cookbook-5.1 对字典排序
开发语言·数据结构·python
老歌老听老掉牙8 小时前
平面旋转与交线投影夹角计算
python·线性代数·平面·sympy
满怀10158 小时前
Python入门(7):模块
python
无名之逆8 小时前
Rust 开发提效神器:lombok-macros 宏库
服务器·开发语言·前端·数据库·后端·python·rust
你觉得2058 小时前
哈尔滨工业大学DeepSeek公开课:探索大模型原理、技术与应用从GPT到DeepSeek|附视频与讲义下载方法
大数据·人工智能·python·gpt·学习·机器学习·aigc
啊喜拔牙8 小时前
1. hadoop 集群的常用命令
java·大数据·开发语言·python·scala
__lost9 小时前
Pysides6 Python3.10 Qt 画一个时钟
python·qt