pyecharts_Bar

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

Bar: 柱状图/条形图

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Bar(init_opts=opts.InitOpts())
.add_xaxis(x_data)
.add_yaxis(y_data)
# 系列配置项
.set_series_opts()
# 全局配置项
.set_global_opts(
title_opts=opts.TitleOpts(title="标题"),
# 工具箱选择项
toolbox_opts=opts.ToolboxOpts(),
# 图例配置项
legend_opts=opts.legendOpts(is_show=False),
# 坐标轴配置项
yaxis_opts=opts.AxisOpts(type_="value"),
# 原生图形元素组件
opts.GraphicGroup(graphic_item=opts.GraphicItem())
)
.render()
  • .add_yaxis()

    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
    100
    101
    102
    103
    104
    def add_yaxis(
    # 系列名称,用于 tooltip 的显示,legend 的图例筛选。
    series_name: str,

    # 系列数据
    y_axis: Sequence[Numeric, opts.BarItem, dict],

    # 是否选中图例
    is_selected: bool = True,

    # 使用的 x 轴的 index,在单个图表实例中存在多个 x 轴的时候有用。
    xaxis_index: Optional[Numeric] = None,

    # 使用的 y 轴的 index,在单个图表实例中存在多个 y 轴的时候有用。
    yaxis_index: Optional[Numeric] = None,

    # 是否启用图例 hover 时的联动高亮
    is_legend_hover_link: bool = True,

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

    # 是否显示柱条的背景色。通过 backgroundStyle 配置背景样式。
    is_show_background: bool = False,

    # 每一个柱条的背景样式。需要将 showBackground 设置为 true 时才有效。
    background_style: types.Union[types.BarBackground, dict, None] = None,

    # 数据堆叠,同个类目轴上系列配置相同的 stack 值可以堆叠放置。
    stack: Optional[str] = None,

    # 柱条的宽度,不设时自适应。
    # 可以是绝对值例如 40 或者百分数例如 '60%'。百分数基于自动计算出的每一类目的宽度。
    # 在同一坐标系上,此属性会被多个 'bar' 系列共享。此属性应设置于此坐标系中最后一个 'bar' 系列上才会生效,并且是对此坐标系中所有 'bar' 系列生效。
    bar_width: types.Union[types.Numeric, str] = None,

    # 柱条的最大宽度。比 barWidth 优先级高。
    bar_max_width: types.Union[types.Numeric, str] = None,

    # 柱条的最小宽度。在直角坐标系中,默认值是 1。否则默认值是 null。比 barWidth 优先级高。
    bar_min_width: types.Union[types.Numeric, str] = None,

    # 柱条最小高度,可用于防止某数据项的值过小而影响交互。
    bar_min_height: types.Numeric = 0,

    # 同一系列的柱间距离,默认为类目间距的 20%,可设固定值
    category_gap: Union[Numeric, str] = "20%",

    # 不同系列的柱间距离,为百分比(如 '30%',表示柱子宽度的 30%)。
    # 如果想要两个系列的柱子重叠,可以设置 gap 为 '-100%'。这在用柱子做背景的时候有用。
    gap: Optional[str] = "30%",

    # 是否开启大数据量优化,在数据图形特别多而出现卡顿时候可以开启。
    # 开启后配合 largeThreshold 在数据量大于指定阈值的时候对绘制进行优化。
    # 缺点:优化后不能自定义设置单个数据项的样式。
    is_large: bool = False,

    # 开启绘制优化的阈值。
    large_threshold: types.Numeric = 400,

    # 使用 dimensions 定义 series.data 或者 dataset.source 的每个维度的信息。
    # 注意:如果使用了 dataset,那么可以在 dataset.source 的第一行/列中给出 dimension 名称。
    # 于是就不用在这里指定 dimension。
    # 但是,如果在这里指定了 dimensions,那么 ECharts 不再会自动从 dataset.source 的第一行/列中获取维度信息。
    dimensions: types.Union[types.Sequence, None] = None,

    # 当使用 dataset 时,seriesLayoutBy 指定了 dataset 中用行还是列对应到系列上,也就是说,系列“排布”到 dataset 的行还是列上。可取值:
    # 'column':默认,dataset 的列对应于系列,从而 dataset 中每一列是一个维度(dimension)。
    # 'row':dataset 的行对应于系列,从而 dataset 中每一行是一个维度(dimension)。
    series_layout_by: str = "column",

    # 如果 series.data 没有指定,并且 dataset 存在,那么就会使用 dataset。
    # datasetIndex 指定本系列使用那个 dataset。
    dataset_index: types.Numeric = 0,

    # 是否裁剪超出坐标系部分的图形。柱状图:裁掉所有超出坐标系的部分,但是依然保留柱子的宽度
    is_clip: bool = True,

    # 柱状图所有图形的 zlevel 值。
    z_level: types.Numeric = 0,

    # 柱状图组件的所有图形的z值。控制图形的前后顺序。
    # z值小的图形会被z值大的图形覆盖。
    # z相比zlevel优先级更低,而且不会创建新的 Canvas。
    z: types.Numeric = 2,

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

    # 标记点配置项,参考 `series_options.MarkPointOpts`
    markpoint_opts: Union[opts.MarkPointOpts, dict, None] = None,

    # 标记线配置项,参考 `series_options.MarkLineOpts`
    markline_opts: Union[opts.MarkLineOpts, dict, None] = None,

    # 提示框组件配置项,参考 `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. BarItem:柱状图数据项
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    class BarItem(
    # 数据项名称。
    name: Optional[str] = None,

    # 单个数据项的数值。
    value: Optional[Numeric] = None,

    # 单个柱条文本的样式设置,参考 `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,
    )
  2. BarBackgroundStyleOpts:柱状图背景样式配置
    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
    class BarBackgroundStyleOpts(
    # 柱条的颜色。
    color: str = "rgba(180, 180, 180, 0.2)",

    # 柱条的描边颜色。
    border_color: str = "#000",

    # 柱条的描边宽度,默认不描边。
    border_width: Numeric = 0,

    # 柱条的描边类型,默认为实线,支持 'dashed', 'dotted'。
    border_type: str = "solid",

    # 圆角半径,单位px,支持传入数组分别指定 4 个圆角半径。 如:
    # barBorderRadius: 5, // 统一设置四个角的圆角大小
    # barBorderRadius: [5, 5, 0, 0] //(顺时针左上,右上,右下,左下)
    bar_border_radius: Union[Numeric, Sequence] = 0,

    # 图形阴影的模糊大小。
    # 该属性配合 shadowColor,shadowOffsetX, shadowOffsetY 一起设置图形的阴影效果。
    shadow_blur: Optional[Numeric] = None,

    # 阴影颜色。支持的格式同color。
    shadow_color: Optional[str] = None,

    # 阴影水平方向上的偏移距离。
    shadow_offset_x: Numeric = 0,

    # 阴影垂直方向上的偏移距离。
    shadow_offset_y: Numeric = 0,

    # 图形透明度。支持从 0 到 1 的数字,为 0 时不绘制该图形。
    opacity: Optional[Numeric] = None,
    )