Skip to content

Latest commit

 

History

History
52 lines (46 loc) · 1.58 KB

sankey_with_level_setting.md

File metadata and controls

52 lines (46 loc) · 1.58 KB

pyecharts 代码 / 效果

import json

from pyecharts import options as opts
from pyecharts.charts import Sankey

with open("product.json", "r", encoding="utf-8") as f:
    j = json.load(f)
c = (
    Sankey()
    .add(
        "sankey",
        nodes=j["nodes"],
        links=j["links"],
        pos_top="10%",
        levels=[
            opts.SankeyLevelsOpts(
                depth=0,
                itemstyle_opts=opts.ItemStyleOpts(color="#fbb4ae"),
                linestyle_opts=opts.LineStyleOpts(color="source", opacity=0.6),
            ),
            opts.SankeyLevelsOpts(
                depth=1,
                itemstyle_opts=opts.ItemStyleOpts(color="#b3cde3"),
                linestyle_opts=opts.LineStyleOpts(color="source", opacity=0.6),
            ),
            opts.SankeyLevelsOpts(
                depth=2,
                itemstyle_opts=opts.ItemStyleOpts(color="#ccebc5"),
                linestyle_opts=opts.LineStyleOpts(color="source", opacity=0.6),
            ),
            opts.SankeyLevelsOpts(
                depth=3,
                itemstyle_opts=opts.ItemStyleOpts(color="#decbe4"),
                linestyle_opts=opts.LineStyleOpts(color="source", opacity=0.6),
            ),
        ],
        linestyle_opt=opts.LineStyleOpts(curve=0.5),
    )
    .set_global_opts(
        title_opts=opts.TitleOpts(title="Sankey-Level Settings"),
        tooltip_opts=opts.TooltipOpts(trigger="item", trigger_on="mousemove"),
    )
    .render("sankey_with_level_setting.html")
)
<iframe width="100%" height="800px" src="Sankey/sankey_with_level_setting.html"></iframe>