New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature: DataLabels.show_category_name #242
Comments
Can you do this with the PowerPoint UI? |
Yep !
It makes the category name appear along side the series values in data labels. Hope that helps. screen shot for reference: https://drive.google.com/file/d/0B_FxAHf_x3I4ZUc5RGNoV285LXM/view?usp=sharing |
Ah, ok, so I think what you're looking for is DataLabel.text_frame. That's already in place: |
Although, now that you mention it, there does seem to be a |
Thanks. Is there an example of how I can use text_frame to label the pie with the categories? `chart.plots[0].has_data_labels = True chart.plots[0].has_text_frame = True and got: AttributeError: 'PiePlot' object has no attribute 'text_frame'` Without the text_frame piece it was working . . . |
I think you're looking for something like this: data_labels = chart.plots[0].data_labels
for data_label in data_labels:
data_label.text_frame.text = 'foobar' |
Is 'foobar' a list of values corresponding to category names in this case? Also I get an error: TypeError Traceback (most recent call last) TypeError: 'DataLabels' object is not iterable |
You might be on a prior version. I believe that was added in the latest release. I think the categories are on the Plot object. You should refer to the API documentation for details. |
@ngnikhilgoyal: I think you're getting a TypeError because it should be something like this instead: for series in chart.series:
for point in series.points:
point.data_label.text_frame.text = 'foobar' From the docs, a "DataLabels" object is not a collection of "DataLabel" objects but rather properties for the data labels: http://python-pptx.readthedocs.io/en/latest/api/chart.html#datalabels-objects @scanny: This feature would be useful for me too. Specifically, control over the "Label Contains" setting available in the PowerPoint UI. Changing the "Label Position" setting right below it is already supported through the I'd imaging adding a |
+1 Having the Label Contains mapped is a huge help specially when dealing with Pie Charts in order to show percentages together with category names. It would be awesome to have something like: chart.plots[0].data_labels.contains = [
pptx.enum.chart.XL_LABEL_CONTAINS.SERIES_NAME,
pptx.enum.chart.XL_LABEL_CONTAINS.CATEGORY_NAME,
pptx.enum.chart.XL_LABEL_CONTAINS.VALUE,
pptx.enum.chart.XL_LABEL_CONTAINS.PERCENTAGE,
pptx.enum.chart.XL_LABEL_CONTAINS.SHOW_LEADER_LINES,
pptx.enum.chart.XL_LABEL_CONTAINS.LEGEND_KEYS
]
chart.plots[0].data_labels.contains_separator = pptx.enum.chart.XL_LABEL_CONTAINS_SEPARATOR.NEW_LINE |
Added in release v0.6.16 circa November 9, 2018. No access to bubble-size or leader-lines, but the other five are in there as e.g. DataLabels.show_percentage (read/write boolean). |
Hi Scanny, I could see someone has looking for the below input in the library, and it would be very appreciate if you could include this in your next update. I will be grateful for you all the time. Thanks again for your excellent effort, I'm out of words to express. Thanks. chart.plots[0].data_labels.contains_separator = pptx.enum.chart.XL_LABEL_CONTAINS_SEPARATOR.NEW_LINE |
When creating a pie chart, is it possible to add the category names as labels to the chart eliminating the need for the legend ?
chart.plots[0].has_data_labels = True
data_labels = chart.plots[0].data_labels
data_labels.number_format = '0%'
This puts the series values as labels. It would be nice if we can put the category values also.
The text was updated successfully, but these errors were encountered: