我正在尝试使用 python-pptx 制作圆环图。我需要设置自定义孔尺寸,它应该是 holeSize 属性,但我找不到。
谁能帮帮我?
chart = ph.insert_chart(XL_CHART_TYPE.DOUGHNUT, chart_data).chart
s = chart.series[0]
s.format.element.set('holeSize', '70')
请您参考如下方法:
这可能有效,至少如果 c:holeSize 元素已经存在于 XML 中(我相信它会存在)。这可以浓缩成几行,我在这里分别拼出每个步骤以清楚地说明正在发生的事情:
chart = ph.insert_chart(XL_CHART_TYPE.DOUGHNUT, chart_data).chart
# ---the c:doughnutChart parent of c:holeSize is at the plot level---
doughnut_plot = chart.plots[0]
# ---access the <c:doughnutChart> element---
doughnutChart = doughnut_plot._element
# ---from then on it's all lxml calls---
holeSizes = doughnutChart.xpath('./c:holeSize')
if len(holeSizes) == 0:
raise ValueError('sorry, no c:holeSize element present')
holeSize = holeSizes[0]
holeSize.set('val', '70')
