数据可视化-旭日图

from pyecharts.globals import CurrentConfig, NotebookType
 
CurrentConfig.NOTEBOOK_TYPE = NotebookType.JUPYTER_LAB
 
from pyecharts import options as opts
from pyecharts.charts import Sunburst
 
 
def sunburst():
    data = [
        opts.SunburstItem(
            name="爷爷",
            children=[
                opts.SunburstItem(
                    name="李叔叔",
                    value=15,
                    children=[
                        opts.SunburstItem(name="表妹李师师", value=2),
                        opts.SunburstItem(
                            name="表哥李振",
                            value=5,
                            children=[opts.SunburstItem(name="表侄李加", value=2)],
                        ),
                        opts.SunburstItem(name="表姐李丝", value=4),
                    ],
                ),
                opts.SunburstItem(
                    name="爸爸",
                    value=10,
                    children=[
                        opts.SunburstItem(name="", value=5),
                        opts.SunburstItem(name="哥哥李梅", value=1),
                    ],
                ),
            ],
        ),
        opts.SunburstItem(
            name="三爷爷",
            children=[
                opts.SunburstItem(name="李叔叔",
                                  children=[
                                      opts.SunburstItem(name="表哥李靖", value=1),
                                      opts.SunburstItem(name="表妹李静", value=2),
                                  ],
                                  )
            ],
        ),
    ]
 
    c=(
        Sunburst()
            .add(series_name="家庭树旭日图", data_pair=data, radius=[0, "90%"])
            .set_global_opts(title_opts=opts.TitleOpts(title="家庭旭日图"),
                             toolbox_opts=opts.ToolboxOpts())
            .set_series_opts(lable_opts=opts.LabelOpts(formatter="{b}"))
    )
    return c
 
 
sunburst().load_javascript()
sunburst().render('mm.html')

 

posted @ 2021-12-04 18:05  呱呱、、  阅读(129)  评论(0编辑  收藏  举报