简体   繁体   中英

Getting error whenever I try updating powerpoint chart in Python using pptx library

I've been using this code to try to add a value into my new chart. I'm a bit confused with the documentation as I am still new to Python. Basically going off from the example on the website I have the categories East, West and Midwest with values 19.2,21.4,16.7. I want to add the category North with the value 40. When I run this code I get the error: Powerpoint found a problem with content... How can I fix this code so it updates the new data?

Code:

chart = prs.slides[5].shapes[1].chart #chart identified on slide 
chart_data = CategoryChartData()
chart_data.categories = ["East","West","Midwest","North"]
chart_data.add_series = ("Series 1", (19.2,21.4,16.7,40))
chart.replace_data(chart_data)
prs.save('Template_Test_2.pptx')

I'm trying to run excel into it but I just want to get the basics established before I do that. Here's a photo of the chart I have: https://i.stack.imgur.com/PWtkQ.png

Error is due to invalid syntax. Instead should be

chart_data.add_series("Series 1", (19.2,21.4,16.7,40))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM