Line Chart
The LineChart component renders a line chart with optional smoothing, markers, value labels, and category labels.
It is useful for visualizing time series or continuous numerical data.
- class pptx_shapes.charts.line.LineChart(config: LineChartConfig)
- render(data: List[dict], x: float, y: float) List[Shape]
A line chart consists of the following elements:
A polyline connecting all data points (optionally smoothed)
Optional background fill under the curve
Circular markers at each point
Value labels positioned above each point
Category labels (e.g., months) below each point
Configuration
Configuration is done via the :ref:LineChartConfig <line-chart-config>, which includes:
LineConfig – controls color, background and thickness of the line
MarkerConfig – controls appearance of point markers
LabelConfig – controls font styles for value and category labels
LineConfig
- class pptx_shapes.charts.line.LineConfig(color: str = '#fe7a81', background: str = '#fe7a81', background_opacity: float = 0.1, thickness: float = 1.5)
Attributes:
color(str) – color of the line, default:"#fe7a81".background(str) – fill color under the line, default:"#fe7a81".background_opacity(float) – opacity of the fill (0.0–1.0), default:0.1.thickness(float) – thickness of the line, default:1.5.
Example:
line = LineConfig(
color="#fe7a81",
background="#ffddd7",
background_opacity=1,
thickness=1.5
)
MarkerConfig
- class pptx_shapes.charts.line.MarkerConfig(color: str = '#fe7a81', background: str = '#ffffff', radius: float = 0.1, width: float = 1.5, height: float = 8, thickness: float = 1.5)
Attributes:
color(str) – marker border color, default:"#fe7a81".background(str) – marker fill color, default:"#ffffff".radius(float) – marker radius, default:0.1.width(float) – marker width, default:1.5.height(float) – marker height, default:8.thickness(float) – outline thickness, default:1.5.
Example:
marker = MarkerConfig(
radius=0.16,
width=2.6,
height=14,
thickness=2
)
LabelConfig
- class pptx_shapes.charts.line.LabelConfig(size: float = 8, color: str = '#222222', family: str = 'Calibri', height: float = 1)
Attributes:
size(float) – font size of the label, default:8.color(str) – text color, default:"#222222".family(str) – font family used for the text, default:"Calibri".height(float) – vertical space reserved for the label, default:1.
Example:
label = LabelConfig(
color="#fe7a81",
size=12
)
LineChartConfig
- class pptx_shapes.charts.line.LineChartConfig(line: pptx_shapes.charts.line.config.LineConfig = <factory>, marker: pptx_shapes.charts.line.config.MarkerConfig = <factory>, value: pptx_shapes.charts.line.config.LabelConfig = <factory>, label: pptx_shapes.charts.line.config.LabelConfig = <factory>, smooth_count: int = 20)
Attributes:
line(LineConfig) – appearance of the line and background.marker(MarkerConfig) – appearance of point markers.value(LabelConfig) – value text config.label(LabelConfig) – label text config.smooth_count(int) – number of interpolated points for smoothing, default:20.
Example usage
1from pptx_shapes import Presentation
2from pptx_shapes.charts.line import LabelConfig, LineChart, LineChartConfig, LineConfig, MarkerConfig
3from pptx_shapes.shapes import Group
4
5
6def main() -> None:
7 x0, y0 = 1.25, 2
8
9 config = LineChartConfig(
10 line=LineConfig(color="#fe7a81", background="#ffddd7", background_opacity=1, thickness=1.5),
11 marker=MarkerConfig(radius=0.16, width=2.6, height=14, thickness=2),
12 value=LabelConfig(color="#fe7a81", size=12),
13 label=LabelConfig(color="#888888", size=13),
14 smooth_count=20
15 )
16
17 data = [
18 {"value": 6.2, "label": "январь\n2024"},
19 {"value": 4.5, "label": "февраль\n2024"},
20 {"value": 7.1, "label": "март\n2024"},
21 {"value": 7, "label": "апрель\n2024"},
22 {"value": 4.1, "label": "май\n2024"},
23 {"value": 5.3, "label": "июнь\n2024"},
24 {"value": 6.1, "label": "июль\n2024"},
25 {"value": 5.9, "label": "август\n2024"},
26 {"value": 9.3, "label": "сентябрь\n2024"},
27 {"value": 8.5, "label": "октябрь\n2024"},
28 {"value": 10.1, "label": "ноябрь\n2024"},
29 {"value": 8.2, "label": "декабрь\n2024"}
30 ]
31
32 with Presentation(presentation_path="../empty.pptx") as presentation:
33 chart = LineChart(config=config)
34 presentation.add(shape=Group(chart.render(data=data, x=x0, y=y0)))
35 presentation.save("line_chart.pptx")
36
37
38if __name__ == "__main__":
39 main()
It creates a line chart where:
Line is styled with a colored stroke and filled background
Markers are placed at each data point
Value labels appear above each marker
Multi-line category labels appear below each marker
Result
This script produces a file line_chart.pptx with a line chart rendered on a blank slide.
Each point shows a value and a category label (typically a month and year).
The line is optionally smoothed and styled via config parameters.
You can adjust smoothing, line appearance, markers and text styling via configuration.