提示:仅供我的舍友学习使用。
代码如下(示例):
from PreTest import *
from pyecharts import options as opts
from pyecharts.render import make_snapshot
from snapshot_phantomjs import snapshot
from pyecharts.charts import Sunburst
data = [
opts.SunburstItem(
name="Grandpa",
children=[
opts.SunburstItem(
name="Uncle Leo",
value=15,
children=[
opts.SunburstItem(name="Cousin Jack", value=2),
opts.SunburstItem(
name="Cousin Mary",
value=5,
children=[opts.SunburstItem(name="Jackson", value=2)],
),
opts.SunburstItem(name="Cousin Ben", value=4),
],
),
opts.SunburstItem(
name="Father",
value=10,
children=[
opts.SunburstItem(name="Me", value=5),
opts.SunburstItem(name="Brother Peter", value=1),
],
),
],
),
opts.SunburstItem(
name="Nancy",
children=[
opts.SunburstItem(
name="Uncle Nike",
children=[
opts.SunburstItem(name="Cousin Betty", value=1),
opts.SunburstItem(name="Cousin Jenny", value=2),
],
)
],
),
]
def sunburst_chart() -> Sunburst:
# ********* Begin *********#
sunburst = (
Sunburst(init_opts=opts.InitOpts(width="1000px", height="600px"))
.add(series_name="", data_pair=data, radius=[0, "90%"])
.set_global_opts(title_opts=opts.TitleOpts(title="Sunburst-基本示例"))
.set_series_opts(label_opts=opts.LabelOpts(formatter="{b}"))
)
# ********** End **********#
return sunburst
make_snapshot(snapshot, sunburst_chart().render("Result/render.html"), 'StudentAnswer/student_answer.png') # 输出图片
make_snapshot(snapshot, sunburst_base(data).render(), "StandardAnswer/task1/standard_answer_1.png")
代码如下(示例):
from PreTest import *
from pyecharts import options as opts
from pyecharts.render import make_snapshot
from snapshot_phantomjs import snapshot
from pyecharts.charts import Sunburst
import json
with open("data.json", "r", encoding="utf-8") as f:
data = json.load(f)
def sunburst_chart() -> Sunburst:
# ********* Begin *********#
sunburst = (
Sunburst(init_opts=opts.InitOpts(width="1000px", height="600px"))
.add(
"",
data_pair=data,
highlight_policy="descendant",
radius=[0, "95%"],
sort_="null",
levels=[
{},
{
"r0": "15%",
"r": "35%",
"itemStyle": {"borderWidth": 2},
"label": {"rotate": "tangential"},
},
{"r0": "35%", "r": "70%", "label": {"align": "right"}},
{
"r0": "70%",
"r": "72%",
"label": {"position": "outside", "padding": 3, "silent": False},
"itemStyle": {"borderWidth": 3},
},
]
)
.set_global_opts(title_opts=opts.TitleOpts(title="Sunburst-官方示例"))
.set_series_opts(label_opts=opts.LabelOpts(formatter="{b}"))
)
# ********** End **********#
return sunburst
make_snapshot(snapshot, sunburst_chart().render("Result/render.html"), "StudentAnswer/student_answer.png") # 输出图片
make_snapshot(snapshot, sunburst_drink_favor(data).render(), "StandardAnswer/task2/standard_answer_2.png")