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

∥☆過路亽.° 提交于 2019-12-24 00:39:34

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/33839588/google-charts-google-sheets-specified-range-does-not-identify-data-correctly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!