I'd like to use the python-pptx library to read data from charts inside a presentation. I've seen the documentation to replace chart data, but I can't figure out how to read data.
1 Answer
Chart data is:
- the chart's chart-type
- its category names (and possibly hierarchical organization)
- its series names
- and its series values
These are available at the plot level, for example:
>>> chart.chart_type
DOUGHNUT
>>> plot = chart.plots[0]
>>> category_labels = [c.label for c in plot.categories]
["West", "North", "South"]
>>> series = plot.series[0]
>>> series.name
'Sales'
>>> series.values
(17.8, 24.5, 88.0)
There are subtleties depending on the chart/plot type. Consult the API document here to learn more about those. https://python-pptx.readthedocs.io/en/latest/api/chart.html
3 Comments
Rajat
you can get the chart_type of a chart you just created. How can you get the chart_type of chart that's already existing in the presentation? Can you read the underlying data of the chart that already exists in the presentation?
scanny
That's a separate question @Rajat. If you open a new question (after searching for an existing answer) we can take a look.
Rajat
I did and you have answered it (stackoverflow.com/questions/66126040/…). I've put my comment there, thank you.