forked from pyecharts/pyecharts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsunburst_example.py
99 lines (89 loc) · 3.04 KB
/
sunburst_example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import json
import os
from pyecharts import options as opts
from pyecharts.charts import Page, Sunburst
from pyecharts.faker import Collector
C = Collector()
@C.funcs
def sunburst_base() -> 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),
],
)
],
),
]
c = (
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}"))
)
return c
@C.funcs
def sunburst_official() -> Sunburst:
with open(os.path.join("fixtures", "drink.json"), "r", encoding="utf-8") as f:
j = json.load(f)
c = (
Sunburst(init_opts=opts.InitOpts(width="1000px", height="600px"))
.add(
"",
data_pair=j,
highlight_policy="ancestor",
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}"))
)
return c
Page().add(*[fn() for fn, _ in C.charts]).render()