Marcos Augusto
Marcos Augusto

Reputation: 41

word wrap data labels python-pptx

Is it possible to set word wrap to false all data labels in my chart?

I was trying to do plots[0].data_labels.format.text_frame.word_wrap = False but data_labels hasn't format property

Upvotes: 3

Views: 1453

Answers (1)

scanny
scanny

Reputation: 29031

Start with the DataLabels object. This is available on the .data_labels attribute of a plot or a series. You might want to try both to see what behavior you get:

from pptx.text.text import TextFrame

# ---obtain reference to <c:dLbls> element in question---
data_labels = plot2.data_labels
dLbls = data_labels._element
# ---use its <c:txPr> child to create TextFrame object---
text_frame = TextFrame(dLbls.get_or_add_txPr(), None)
# ---turn off word-wrap in the usual way---
text_frame.word_wrap = False

This can be made more compact, I show it step-by-step here for clarity.

Upvotes: 5

Related Questions