mirror of
https://github.com/pyecharts/pyecharts.git
synced 2025-12-08 20:59:23 +00:00
70 lines
1.7 KiB
Python
70 lines
1.7 KiB
Python
# coding=utf-8
|
|
from pyecharts import options as opts
|
|
from pyecharts.charts import Page, Pie
|
|
|
|
from example.commons import Faker
|
|
|
|
charts = []
|
|
|
|
|
|
def collect_charts(fn):
|
|
charts.append((fn, fn.__name__))
|
|
return fn
|
|
|
|
|
|
@collect_charts
|
|
def pie_base() -> Pie:
|
|
c = (
|
|
Pie()
|
|
.add("", [list(z) for z in zip(Faker.choose(), Faker.values())])
|
|
.set_global_opts(title_opts=opts.TitleOpts(title="Pie-基本示例"))
|
|
.set_series_opts(label_opts=opts.LabelOpts(formatter="{b}: {c}"))
|
|
)
|
|
return c
|
|
|
|
|
|
@collect_charts
|
|
def pie_radius() -> Pie:
|
|
c = (
|
|
Pie()
|
|
.add(
|
|
"",
|
|
[list(z) for z in zip(Faker.choose(), Faker.values())],
|
|
radius=["40%", "75%"],
|
|
)
|
|
.set_global_opts(
|
|
title_opts=opts.TitleOpts(title="Pie-Radius"),
|
|
legend_opts=opts.LegendOpts(orient="vertical", top="15%", left="2%"),
|
|
)
|
|
.set_series_opts(label_opts=opts.LabelOpts(formatter="{b}: {c}"))
|
|
)
|
|
return c
|
|
|
|
|
|
@collect_charts
|
|
def pie_rosetype() -> Pie:
|
|
v = Faker.choose()
|
|
c = (
|
|
Pie()
|
|
.add(
|
|
"",
|
|
[list(z) for z in zip(v, Faker.values())],
|
|
radius=["30%", "75%"],
|
|
center=["25%", "50%"],
|
|
rosetype="radius",
|
|
label_opts=opts.LabelOpts(is_show=False),
|
|
)
|
|
.add(
|
|
"",
|
|
[list(z) for z in zip(v, Faker.values())],
|
|
radius=["30%", "75%"],
|
|
center=["75%", "50%"],
|
|
rosetype="area",
|
|
)
|
|
.set_global_opts(title_opts=opts.TitleOpts(title="Pie-玫瑰图示例"))
|
|
)
|
|
return c
|
|
|
|
|
|
Page().add(*[fn() for fn, _ in charts]).render()
|