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.
Asked
Active
Viewed 2,753 times
1 Answers
4
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

scanny
- 26,423
- 5
- 54
- 80
-
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? – Rajat Feb 09 '21 at 20:46
-
That's a separate question @Rajat. If you open a new question (after searching for an existing answer) we can take a look. – scanny Feb 09 '21 at 21:39
-
I did and you have answered it (https://stackoverflow.com/questions/66126040/read-data-embedded-in-pptx-chart/66127557#66127557). I've put my comment there, thank you. – Rajat Feb 10 '21 at 16:25