Boosted_d16
Boosted_d16

Reputation: 14082

python-pptx - cannot update one data point's datalabel text

I'm trying to update the text for 1 specific data label but it turns off the data labels for its siblings.

#turn on data labels
plot = chart.plots[0]
plot.has_data_labels = True

#add custom text to the 1st series' 1st data point. Ignore the rest.
plot.series[1].points[1].data_label.text_frame.text = '▲'

This is what it does, notice how the data labels for plot.series[1].points[0] and plot.series[1].points[2] are now turned off.

enter image description here

Expected output:

enter image description here

Upvotes: 2

Views: 628

Answers (1)

scanny
scanny

Reputation: 28933

Yeah, that's how PowerPoint does it; series-level data-label settings do not cascade down to the data-point level. You either use the labels generated at the series level for all categories in the series or you have to specify each one of them at the datapoint level. What the PowerPoint app does is add a copy of the series-level label properties on each of the data-points when you edit a label for a single datapoint; that's why it looks like you can just change a single one when working in the PowerPoint app.

python-pptx doesn't do that preemptive copy, so setting a data label at the data-point level seems to "shut-off" all other data labels.

In any case, you'll need to specify all data-point level labels for a series if you want to change one or more of them.

Upvotes: 2

Related Questions