Bar Chart

The BarChart component allows you to render bar charts composed of rectangles, value labels, and category labels. This chart is useful for visualizing categorical time series or grouped values.

class pptx_shapes.charts.bar.BarChart(config: BarChartConfig)
render(data: List[dict], x: float, y: float) List[Shape]

A bar chart consists of the following elements:

  • Vertical bars representing data values (with proportional heights)

  • Value labels positioned above each bar

  • Category labels (e.g., month/year) positioned below each bar

Configuration

Configuration is done via the BarChartConfig, which includes:

  • BarConfig — controls bar width, height, radius, stroke and fill

  • LabelConfig — controls font styles for value and category labels

BarConfig

class pptx_shapes.charts.bar.BarConfig(width: float = 1.2, height: float = 8, radius: float = 0.2, fill_color: str = '#ffc154', stroke_color: str = '#ffffff', thickness: float = 1)

Attributes:

  • width (int) – width of the bar, default: 1.2.

  • height (int) – max height of the bars, default: 8.

  • radius (float) – rounding radius of bars, default: 0.2.

  • fill_color (str) – bar fill color, default: "#ffc154".

  • stroke_color (str) – bar outline color, default: "#ffffff".

  • thickness (str) – bar outline thickness, default: 1.

Example:

bar = BarConfig(
    width=2,
    height=15,
    radius=0,
    fill_color="red",
    thickness=2
)

LabelConfig

class pptx_shapes.charts.bar.LabelConfig(size: float = 8, color: str = '#222222', family: str = 'Calibri', height: float = 1)

Attributes:

  • size (int) – font size of the label, default: 8.

  • color (str) – text color, default: "#222222".

  • family (str) – font family used for the text, default: "Calibri".

Example:

label = LabelConfig(
    size=10,
    color="blue",
    family="Arial",
)

BarChartConfig

class pptx_shapes.charts.bar.BarChartConfig(bar: pptx_shapes.charts.bar.config.BarConfig = <factory>, value: pptx_shapes.charts.bar.config.LabelConfig = <factory>, label: pptx_shapes.charts.bar.config.LabelConfig = <factory>)

Attributes:

Example usage

 1from pptx_shapes import Presentation
 2from pptx_shapes.charts.bar import BarChart, BarChartConfig, BarConfig, LabelConfig
 3from pptx_shapes.shapes import Group
 4
 5
 6def main() -> None:
 7    x0, y0 = 0.9, 2
 8
 9    config = BarChartConfig(
10        bar=BarConfig(width=2, height=15, thickness=2),
11        value=LabelConfig(size=14, color="#222"),
12        label=LabelConfig(size=12, color="#222")
13    )
14
15    data = [
16        {"value": 12, "label": "январь\n2024"},
17        {"value": 19, "label": "февраль\n2024"},
18        {"value": 20, "label": "март\n2024"},
19        {"value": 24, "label": "апрель\n2024"},
20        {"value": 27, "label": "май\n2024"},
21        {"value": 27, "label": "июнь\n2024"},
22        {"value": 34, "label": "июль\n2024"},
23        {"value": 38, "label": "август\n2024"},
24        {"value": 49, "label": "сентябрь\n2024"},
25        {"value": 34, "label": "октябрь\n2024"},
26        {"value": 42, "label": "ноябрь\n2024"},
27        {"value": 35, "label": "декабрь\n2024"},
28        {"value": 10, "label": "январь\n2025"},
29        {"value": 45, "label": "февраль\n2025"},
30        {"value": 12, "label": "март\n2025"},
31        {"value": 19, "label": "апрель\n2025"}
32    ]
33
34    with Presentation(presentation_path="../empty.pptx") as presentation:
35        chart = BarChart(config=config)
36        presentation.add(shape=Group(chart.render(data=data, x=x0, y=y0)))
37        presentation.save("bar_chart.pptx")
38
39
40if __name__ == "__main__":
41    main()

It creates a bar chart where:

  • Bars are 2 cm wide and up to 15 cm high

  • Value labels appear above each bar

  • Multi-line category labels appear below each bar

Result

This script produces a file bar_chart.pptx with a visually styled bar chart on a blank slide. Each bar represents a month, with value labels and month-year captions.

Bar chart example

You can adjust bar dimensions, text styles, and spacing through the config objects.

Note

The height of each bar is normalized relative to the maximum value in the data.