简体   繁体   中英

Google Charts + Google Sheets: Specified range does not identify data correctly

I settled on using Google Charts to draw the data from an auto-updating Google Sheet that draws from my Analytics account (the analytic API wasn't working out).

I've done quite a lot of reading, but I'm finding the query language reference to be a pain.

I've chosen to use the ChartWrapper.

https://jsfiddle.net/7xzv59kj/2/

     // Visits
      var wrap = new google.visualization.ChartWrapper();
      wrap.setChartType('ColumnChart');
           wrap.setDataSourceUrl('https://docs.google.com/spreadsheets/d/1jICOBDvZzRxEThcWqnpFmNLUqjVP81Zd9RTwpbG29cE/gviz/tq?sheet=Sheet2&range=Keywords-All_Time!B11:C12&headers=1&tq=');
      wrap.setContainerId('visits-all-time');
      wrap.draw();
  }

I want the chart to display the labels for Users and Sessions on the H-Axis, and then the values on the V-Axis. Instead, the data gets all jumbled and confused. I don't know what parameters to specify and how to label them properly.

Spreadsheet located here.

https://docs.google.com/spreadsheets/d/1jICOBDvZzRxEThcWqnpFmNLUqjVP81Zd9RTwpbG29cE

I would like to draw the data from the sheet titled Keywords-All_Time from range B11:C12

The issue here was just my foggy brain - I took a break and came back to it yesterday to discover a couple issues:

  wrap.setDataSourceUrl('https://docs.google.com/spreadsheets/d/1jICOBDvZzRxEThcWqnpFmNLUqjVP81Zd9RTwpbG29cE/gviz/tq?sheet=Sheet2&range=Keywords-All_Time!B11:C12&headers=1&tq=');
  1. My URL specifies the sheet twice. I recall someone telling me to format the range with the sheet, but I suppose I never erased the other parameter.

  2. My table had the axes the wrong way around. I reversed them and found everything worked well from there.

I abandoned the chart wrapper and decided to move on to that when I actually have a need for it. Here's the current jsfiddle with the code I'm working on now: https://jsfiddle.net/c11c9a0w/19/

This will be extremely helpful for anyone having trouble building a dynamic dashboard from a Google Sheet that has multiple graphs on a single page, so feel free to work off of this.

-Joel

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM