6

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 1

6

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

Sign up to request clarification or add additional context in comments.

3 Comments

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?
That's a separate question @Rajat. If you open a new question (after searching for an existing answer) we can take a look.
I did and you have answered it (stackoverflow.com/questions/66126040/…). I've put my comment there, thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.