Skip to content
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

Chart Data Alignment #440

Open
akashsharma03 opened this issue Sep 21, 2018 · 5 comments
Open

Chart Data Alignment #440

akashsharma03 opened this issue Sep 21, 2018 · 5 comments

Comments

@akashsharma03
Copy link

Hi,

Is there any way to find out if the data on the chart is plot by row or plot by column
In other words the series values on the chart data worksheet are in columns or rows.

Thanks in Advance.

@scanny
Copy link
Owner

scanny commented Sep 21, 2018

Say more about your situation and what you're trying to accomplish. Your question so far is too abstract; the only answer I could give to it as it stands is "Yes".

@akashsharma03
Copy link
Author

Attaching a screenshot
snip

in this picture you can see 'Q1 Sales, Q2 Sales, Q3 Sales' are series that are columns in the chart data sheet. But when you switch row/columns, they become categories and now the series are ' East West Midwest' , which are rows in the chart data.

I want a way to figure out if my series are columns or rows in chart data.

@scanny
Copy link
Owner

scanny commented Sep 24, 2018

I think the only way you'll be able to do this is to parse the Excel range expression. You might be able to access that like this:

ser = series._ser
print(ser.xml)
f = ser.xpath('./c:val/c:numRef/c:f')[0]
print(f.text)

Which gets you something like: 'Sheet1!$B$2:$F$2'

Either the columns (letters B and F in this case) will be the same, or the rows (number 2 in this case) will be the same. That will tell you how the data is arrayed in the Excel spreadsheet.

@akashsharma03
Copy link
Author

Hi Steve,

Great tip. Thanks Man.

xpath seems to be very useful sometime. Any tip how can I access and understand these to implement it specific to my requirements rather than bothering you everytime .

@scanny
Copy link
Owner

scanny commented Sep 25, 2018

Each new feature starts with an enhancement proposal, also known as an analysis page, like this one:
https://python-pptx.readthedocs.io/en/latest/dev/analysis/cht-series.html

These are part of the documentation, you get to them using the "Analysis" link at the bottom of the documentation home page.

Each of those generally has a section entitled "Specimen XML" where you can see what the underlying XML looks like. From there, you get as close as you can by getting the ._element of a proxy object (like series in this case) (sometimes these are only named for the underlying element, like ser in this case for a <c:ser> element, in that case you might have to glance at the code to find the right spelling).

Once you have an element and a view of its children, you can use XPath to access arbitrary elements and/or attributes within that subtree (or even above actually). You can find XPath answers with quick search usually, and tutorials are plentiful as well. Then you just need enough understanding of the lxml properties and methods you need to work with elements. f.text is one of these; f is an instance of lxml.etree._Element which has a property .text which gives you what's inside the element.
https://lxml.de/api/lxml.etree._Element-class.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants