Using Google Sheets data for Google Chart Table. How do I indicate Sheets data headers should be used as Table headers?

301 views
Skip to first unread message

Andrew Castellano

unread,
Dec 16, 2014, 2:26:17 PM12/16/14
to google-visua...@googlegroups.com
js fiddle: http://jsfiddle.net/awcastellano/a1qbju32/9/

The headers in the Google Sheet are: Team/QA/DS

When queried and sent to the Table they are inserted as plain cell data (understandable since I didn't indicate the first row is a header). The question is, how do I indicate the first row of the Sheet be used as a header in the Table?

I promise I looked around, I couldn't find anything and kept going in circles.

Andrew Castellano

unread,
Dec 17, 2014, 10:02:25 AM12/17/14
to google-visua...@googlegroups.com
Sorry guys, realizing that this fiddle won't work for anyone but me... I guess that's my new problem. Does anyone knows why it would say "dataTable is not defined" for everyone but me? Since I'm the only one that can see it, and the data is being pulled from a Google Sheet, would it have to do with user permission to that sheet? Even though I published it?

Andrew Castellano

unread,
Dec 17, 2014, 10:11:16 AM12/17/14
to google-visua...@googlegroups.com
Ok, so when I sign out of google, it doesn't work for me either...

Daniel LaLiberte

unread,
Dec 17, 2014, 10:41:12 AM12/17/14
to google-visua...@googlegroups.com
Hi Andrew,

Your response handler should check for errors.  See the isError() and getMessage() methods on: https://developers.google.com/chart/interactive/docs/reference#Query

When there is an error, the data table will be null.

The permission problem is that, if you are not logged in, Google Charts can't offer you a login dialog in order to get access to the spreadsheet.

As for how to indicate that the first row of the sheet will be used as a header, there is no way currently, at least not on the Google Charts side.  Perhaps if you specify the format of the first row in your spreadsheet as text, and format the columns otherwise as numbers, the spreadsheet would have enough info to decide that your first row should be treated specially.  

Another approach is to first get all the data, including your header row, and then pull it apart in your query response handler, and construct a DataView from all but the first row, and define the columns based on your header row.  See https://developers.google.com/chart/interactive/docs/reference#DataView and the setRows() and setColumns() methods.

Hope that helps give you some clues about how to proceed.


--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualizati...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/d/optout.



--
dlaliberte@Google.com   5CC, Cambridge MA
daniel.laliberte@GMail.com 9 Juniper Ridge Road, Acton MA

Andrew Castellano

unread,
Dec 29, 2014, 9:26:43 AM12/29/14
to google-visua...@googlegroups.com
Hey just wanted to stop in and say thanks for the response Daniel! This project has been pushed to the side for me right now which is why I haven't responded. Once I get the chance to work through this I will update my post again for anyone who might have a similar question.


On Wednesday, December 17, 2014 10:41:12 AM UTC-5, Daniel LaLiberte wrote:
Hi Andrew,

Your response handler should check for errors.  See the isError() and getMessage() methods on: https://developers.google.com/chart/interactive/docs/reference#Query

When there is an error, the data table will be null.

The permission problem is that, if you are not logged in, Google Charts can't offer you a login dialog in order to get access to the spreadsheet.

As for how to indicate that the first row of the sheet will be used as a header, there is no way currently, at least not on the Google Charts side.  Perhaps if you specify the format of the first row in your spreadsheet as text, and format the columns otherwise as numbers, the spreadsheet would have enough info to decide that your first row should be treated specially.  

Another approach is to first get all the data, including your header row, and then pull it apart in your query response handler, and construct a DataView from all but the first row, and define the columns based on your header row.  See https://developers.google.com/chart/interactive/docs/reference#DataView and the setRows() and setColumns() methods.

Hope that helps give you some clues about how to proceed.

On Wed, Dec 17, 2014 at 10:02 AM, Andrew Castellano <awcast...@gmail.com> wrote:
Sorry guys, realizing that this fiddle won't work for anyone but me... I guess that's my new problem. Does anyone knows why it would say "dataTable is not defined" for everyone but me? Since I'm the only one that can see it, and the data is being pulled from a Google Sheet, would it have to do with user permission to that sheet? Even though I published it?



On Tuesday, December 16, 2014 2:26:17 PM UTC-5, Andrew Castellano wrote:
js fiddle: http://jsfiddle.net/awcastellano/a1qbju32/9/

The headers in the Google Sheet are: Team/QA/DS

When queried and sent to the Table they are inserted as plain cell data (understandable since I didn't indicate the first row is a header). The question is, how do I indicate the first row of the Sheet be used as a header in the Table?

I promise I looked around, I couldn't find anything and kept going in circles.

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsub...@googlegroups.com.

To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/d/optout.



--
dlali...@Google.com   5CC, Cambridge MA
daniel.l...@GMail.com 9 Juniper Ridge Road, Acton MA
Reply all
Reply to author
Forward
0 new messages