pyecharts_Pie

全部来自于官方文档,主要用于方便自己查找

Pie:饼图

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
from pyecharts.charts import Pie
import pyecharts.options as opts
# .fake 伪造数据生成器,具体看内部代码
from pyecharts.faker import Faker

# 生成多维数组 eg:[['周一', 127], ['周二', 111], ['周三', 61], ['周四', 94], ['周五', 93], ['周六', 51], ['周日', 47]]
data=[list(z) for z in zip(Faker.choose(), Faker.values())]
# 颜色列表,与 data 中数据一一对应
color = []
c = (
Pie()
.add(series_name='', data_pair=data)
.set_colors(color)
.set_global_opts(title_opts=opts.TitleOpts(title="主标题"))
# 生成 饼图外标 "周一: 127"
.set_series_opts(label_opts=opts.LabelOpts(formatter="{b}:{c}"))
.render('xxx.html')
)
  • .add()
    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
    def add(
    # 系列名称,用于 tooltip 的显示,legend 的图例筛选。
    series_name: str,

    # 系列数据项,格式为 [(key1, value1), (key2, value2)]
    data_pair: types.Sequence[types.Union[types.Sequence, opts.PieItem, dict]],

    # 系列 label 颜色
    color: Optional[str] = None,

    # 饼图的半径,数组的第一项是内半径,第二项是外半径
    # 默认设置成百分比,相对于容器高宽中较小的一项的一半
    radius: Optional[Sequence] = None,

    # 饼图的中心(圆心)坐标,数组的第一项是横坐标,第二项是纵坐标
    # 默认设置成百分比,设置成百分比时第一项是相对于容器宽度,第二项是相对于容器高度
    center: Optional[Sequence] = None,

    # 是否展示成南丁格尔图,通过半径区分数据大小,有'radius'和'area'两种模式。
    # radius:扇区圆心角展现数据的百分比,半径展现数据的大小
    # area:所有扇区圆心角相同,仅通过半径展现数据大小
    rosetype: Optional[str] = None,

    # 饼图的扇区是否是顺时针排布。
    is_clockwise: bool = True,

    # 标签配置项,参考 `series_options.LabelOpts`
    label_opts: Union[opts.LabelOpts, dict] = opts.LabelOpts(),

    # 提示框组件配置项,参考 `series_options.TooltipOpts`
    tooltip_opts: Union[opts.TooltipOpts, dict, None] = None,

    # 图元样式配置项,参考 `series_options.ItemStyleOpts`
    itemstyle_opts: Union[opts.ItemStyleOpts, dict, None] = None,

    # 可以定义 data 的哪个维度被编码成什么。
    encode: types.Union[types.JSFunc, dict, None] = None,
    )
  1. PieItem:饼图数据项
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    class PieItem(
    # 数据项名称。
    name: Optional[str] = None,

    # 数据值。
    value: Optional[Numeric] = None,

    # 该数据项是否被选中。
    is_selected: bool = False,

    # 标签配置项,参考 `series_options.LabelOpts`
    label_opts: Union[LabelOpts, dict, None] = None,

    # 图元样式配置项,参考 `series_options.ItemStyleOpts`
    itemstyle_opts: Union[ItemStyleOpts, dict, None] = None,

    # 提示框组件配置项,参考 `series_options.TooltipOpts`
    tooltip_opts: Union[TooltipOpts, dict, None] = None,
    )