Google Visualization API不支持GID或工作表参数

eri*_*cso 7 javascript google-app-engine google-visualization google-spreadsheet-api

我正在使用Google Visualization Javascript API从Google表格中加载图表并将其显示在div中.我的应用程序托管在Google App Engine上.我提供了工作表的URL,其中的参数gid=1用于指定第二个工作表,但显示的图表是第一个工作表.这是我的简化代码(它基本上是文档中提供的示例代码):

// sheetUrl is the URL of the Google sheet, e.g., http://https://docs.google.com/a/google.com/spreadsheet/ccc?key=0AobNU9T3MusKdGFqRHNJYkFnb3RuSkt4QlE#gid=1
// divId is the id of the <div> element I'm displaying in

google.load('visualization', '1.0', {packages: ['table']});
google.setOnLoadCallback(drawChart);

function drawChart() {
    var query = new google.visualization.Query(sheetUrl);
    query.send(handleQueryResponse);
}

function handleQueryResponse(response) {

    var data = response.getDataTable();
    var table = new google.visualization.Table(document.getElementById(divId));
    table.draw(data);
}
Run Code Online (Sandbox Code Playgroud)

您可以#gid=1在URL中看到.我也试过&gid=1&sheet='Volume',这是选项卡的名称,但在页面加载时,从第一标签中的数据被渲染.

我已经注意到我上面的表格中的Google表格网址,但也是以这种形式:

https://docs.google.com/spreadsheet/tq?key=0AobNU9T3MusKdGFqRHNJYkFnb3RuSkt4QlE
Run Code Online (Sandbox Code Playgroud)

我无法找到任何明确解释tq端点的文档.我尝试使用此表单中的URL,但在尝试加载图表时出现超时错误.任何人都遇到这个问题或者对tq事情有所了解?谢谢!

编辑2014-02-17:

我已经更改了我的URL以使用tq端点,我尝试了以下参数:

#gid=1
&gid=1
#sheet=Volume
&sheet=Volume
Run Code Online (Sandbox Code Playgroud)

当我在浏览器中查询url时:

https://docs.google.com/spreadsheet/tq?key=0AobNU9T3MusKdGFqRHNJYkFnb3RuSkt4QlE&sheet=Volume
Run Code Online (Sandbox Code Playgroud)

我得到了合适的纸张.但是当我使用Visualization API进行查询时,我得到了第一张表.

don*_*pep 8

传递给可与新Google表格配合使用的Visualization API的正确网址是以下格式:

https://docs.google.com/spreadsheets/d/{key}/gviz/tq
Run Code Online (Sandbox Code Playgroud)

您可以使用gidquery参数传递要检索的工作表的ID.因此,如果您gid为0,则URL将为:

https://docs.google.com/spreadsheets/d/{key}/gviz/tq?gid=0
Run Code Online (Sandbox Code Playgroud)

您可以在此错误报告中找到有关旧版和新版Google表格的网址格式的其他信息.

希望有所帮助.


小智 6

按工作表名称引用也可以如下工作

https://docs.google.com/spreadsheets/d/{key}/gviz/tq?sheet=MySheetName
Run Code Online (Sandbox Code Playgroud)

确保电子表格是"新"与"旧"Google表格.当我认为我的床单是新的时,我猛烈地抓住那个.一旦我创建了一个新的样式表并使用了donnapep的答案,我就再次工作了.然后我确认使用sheet = sheetname工作也是我真正追求的.