Corey Sailer
Corey Sailer

Reputation: 31

How do u get left,right,bottom and top values from a bar or datalabel

I have a barchart of the type BAR_Clustered. So basicly a Horizontal barchart. I would like to display the category inside the bar and the value outside end. I think its not possible to set 2 diffrent positions for the same datalabel. That's why I am trying to add a Textbox in every bar and just wright in the category. My problem is that i don't know how many bars there will be and where they will be. So my question is. Is there a way to get the top,bottom,left and right values of a bar or a datalabel?

without textbox with textbox

I already searched the pptx docx for some properties with the needed values, but couldn't find something useful.

Upvotes: 2

Views: 318

Answers (1)

scanny
scanny

Reputation: 28933

The short answer is no; you'll need to find some alternative.

You can have more than one "item" in a datalabel, like label + value, but the entire label is one thing and can only have one nominal position (e.g. outside end). So this rules out having a "split-position" data-label.

The position of each bar is not specified in the .pptx file; rather it is calculated at display-time by the renderer. python-pptx does not try to guess where this will be and you would have to do just that (guess as accurately as possible) if you want to place a textbox. The times I've seen folks try this it hasn't worked out well.

So I recommend you find another way to try to work within the limitations of PowerPoint's chart layout. You might place the category labels on the axis (which is their usual location), for example, rather than inside the bar.

If you do something "clever" to work "outside" of PowerPoint's chart layout capability you will likely require a manual "clean-up" step to do final alignment.

Upvotes: 1

Related Questions