2

Replacing data in a certain pie chart with the python-pptx library causes an error. However, replacing the data in another pie chart on the same slide causes no problems.

If I replace the data in only the second pie chart (the one which I encountered errors in changing) it still has the same problem. There is no reason why it should be doing this, as far as I'm aware, as the data that I am trying to put in it is the same data that was already in there. I am on Windows 10 Enterprise (Version 10.0.15063 Build 15063) running python3.7.3 and the latest version of python-pptx.

Replacing the data works fine on the first pie chart, though, so I don't know what the issue could be. They are both on the same slide.

chart = slide.shapes[-2].chart
chart_data = ChartData()
ctg = []
for i in mcdata:
    ctg.append(i+" - "+str(mcdata[i]))
chart_data.categories = tuple(ctg)
chart_data.add_series("",tuple([float(mcdata[i]) for i in mcdata]))
chart.replace_data(chart_data)

mcdata is a dictionary that looks like this:

{"total": 268788, "rejected": 13103, "Virus Signature Detection": 416, "Anti-Spoofing Header Lockout": 66, "Anti-Spoofing Lockout": 470}

In the pie chart that I want to replace the data in, chart.plots[0].categories looks like this:

{"Virus Signature Detection":416, "Anti-Spoofing Header Lockout": 66 ...} etc

chart.series[0].values looks like this:

(416.0, 66.0, ...) etc

When I open the presentation, I get the error message "PowerPoint found a problem with content in out.pptx. PowerPoint can attempt to repair the presentation. If you trust the source of the presentation, click Repair."

When I click repair, it shows another message saying "PowerPoint couldn't read some content in out.pptx [Repaired] and removed it. Please check your presentation to see if the rest of it looks ok." And the entire slide is blank.

GandhiGandhi
  • 1,029
  • 6
  • 10
  • What about when you just use literals on that chart, like `categories = ("Virus", "Spoof"); add_series("Series 1", (1, 2, 3, 4)`? Trying that takes your data source and manipulation out of the equation. – scanny Jul 01 '19 at 16:59
  • @scanny, same exact issue. I used the exact data you suggested. – Marcus Weinberger Jul 01 '19 at 17:05
  • k, I've reopened the GitHub issue and we can inspect the XML there to see what's going on. – scanny Jul 01 '19 at 19:03

0 Answers0