Skip to main content

Chart

A chart object. The root of a hierarchical graph of component objects providing access to chart properties and methods.

Properties

chart_type
XlChartType
Member of XlChartType enumeration specifying type of this chart. If the chart has two plots, the type reported is for the first (back-most) plot. Read-only.
from pptx.enum.chart import XL_CHART_TYPE
if chart.chart_type == XL_CHART_TYPE.COLUMN_CLUSTERED:
    print("This is a clustered column chart")
chart_style
int | None
Integer index of chart style (1-48). None if no explicit style has been assigned. Assigning None removes any explicit setting.
chart.chart_style = 10
has_title
bool
True if chart has a title. Assigning True adds a title if not present. Assigning False removes existing title.
chart.has_title = True
chart.chart_title.text_frame.text = "Sales Report"
chart_title
ChartTitle
ChartTitle object providing access to title properties. Accessing this property adds a chart title element if not present. Use has_title to test non-destructively.
chart.chart_title.text_frame.text = "Q1 Revenue"
chart.chart_title.format.fill.solid()
has_legend
bool
True if the chart has a legend. Assigning True adds a legend if it doesn’t already have one. Assigning False removes existing legend.
chart.has_legend = True
legend
Legend
Legend object providing access to the properties of the legend for this chart.
from pptx.enum.chart import XL_LEGEND_POSITION
chart.legend.position = XL_LEGEND_POSITION.BOTTOM
chart.legend.include_in_layout = False
category_axis
CategoryAxis | DateAxis | ValueAxis
The category axis of this chart. In XY or Bubble charts, this is the X axis. Raises ValueError if no category axis is defined (e.g., pie chart).
chart.category_axis.has_major_gridlines = True
chart.category_axis.tick_labels.font.size = Pt(10)
value_axis
ValueAxis
ValueAxis object providing access to properties of the value axis. Raises ValueError if chart has no value axis.
chart.value_axis.minimum_scale = 0
chart.value_axis.maximum_scale = 100
series
SeriesCollection
SeriesCollection containing all series in this chart. When the chart has multiple plots, all series for the first plot appear before those for the second.
for series in chart.series:
    series.format.fill.solid()
    series.format.fill.fore_color.rgb = RGBColor(0, 100, 200)
plots
_Plots
Sequence of plots in this chart. Most charts have only a single plot. Supports len(), iteration, slicing, and indexed access.
first_plot = chart.plots[0]
first_plot.has_data_labels = True
font
Font
Font object controlling text format defaults for this chart.
from pptx.util import Pt
chart.font.size = Pt(12)
chart.font.name = "Arial"

Methods

replace_data(chart_data)
None
Replace the categories and series values in the XML and Excel worksheet for this chart.
chart_data
ChartData
required
ChartData object containing new data
from pptx.chart.data import CategoryChartData

chart_data = CategoryChartData()
chart_data.categories = ['Q1', 'Q2', 'Q3', 'Q4']
chart_data.add_series('Revenue', (10, 20, 30, 40))

chart.replace_data(chart_data)

ChartTitle

Provides properties for manipulating a chart title.

Properties

text_frame
TextFrame
TextFrame instance allowing read/write access to the text and its formatting. Accessing this property adds a text frame if not present. Use has_text_frame to test non-destructively.
chart.chart_title.text_frame.text = "Sales by Region"
chart.chart_title.text_frame.paragraphs[0].font.size = Pt(16)
has_text_frame
bool
True if this chart title has a text frame. Assigning True adds a text frame if not present. Assigning False removes any existing text frame.
if not chart.chart_title.has_text_frame:
    chart.chart_title.has_text_frame = True
format
ChartFormat
ChartFormat object providing access to line and fill formatting for this chart title.
from pptx.util import RGBColor
chart.chart_title.format.fill.solid()
chart.chart_title.format.fill.fore_color.rgb = RGBColor(200, 200, 200)

Build docs developers (and LLMs) love