因为我尝试使用1个句柄功能同时查询3张3张图表,但它的工作原理是错误的(它在3 div中显示相同的图表)
所以我认为我必须在每个图表上添加句柄功能,如
google.charts.load('current', {packages: ["geochart"]});
google.charts.setOnLoadCallback(drawRegionsMap);
function drawRegionsMap() {
var query1 = new google.visualization.Query("https://docs.google.com/spreadsheets/d/14VouG7zZqHGB9CA6bxQx6CXX-TvOYkSqTmrN5DAj1Do/edit#gid=1175123524");
var query2 = new google.visualization.Query('https://docs.google.com/spreadsheets/d/1RsugJPtz2EdHOLaiL0SvR9bh61H-vAgn9x1QBjIJ--c/edit?usp=sharing');
var query3 = new google.visualization.Query('https://docs.google.com/spreadsheets/d/1zPP22gUPLDqTrvASIU3OXpmeHL_9IBS2O4z75g-1BHY/edit?usp=sharing');
query1.send(handleQueryResponseTR1);
query2.send(handleQueryResponseTR2);
query3.send(handleQueryResponseTR3);
}
function handleQueryResponseTR1(response1) {
if (response1.isError()) {
alert('Error in query: ' + response1.getMessage() + ' ' + response1.getDetailedMessage());
return;
}
function handleQueryResponseTR2(response2) {
if (response2.isError()) {
alert('Error in query: ' + response2.getMessage() + ' ' + response2.getDetailedMessage());
return;
}
function handleQueryResponseTR3(response3) {
if (response3.isError()) {
alert('Error in query: ' + response3.getMessage() + ' ' + response3.getDetailedMessage());
return;
}
var data1 = response1.getDataTable();
var data2 = response2.getDataTable();
var data3 = response3.getDataTable();

但我收到了错误
未定义handleQueryResponseTR2
所以我不知道谷歌图表是否可以在一个页面中查询超过1张?
答案 0 :(得分:1)
我不相信googlechart查询同时存在多个查询的任何问题,以回答这个问题。
关于您的代码:
您的handleQueryResponseTR2函数是handleQueryResponseTR1中的本地函数,但您尝试从drawRegionsMap()调用它。 handleQueryResponseTR2()未在该范围内定义。
将handleQueryResponseTR2()移动到较高范围,使其对调用函数可见。
实际上,将所有handleQueryResponse函数移到上一级。
var data1;
var data2;
var data3;
function handleQueryResponseTR1(response1) {
if (response1.isError()) {
alert('Error in query: ' + response1.getMessage() + ' ' + response1.getDetailedMessage());
return;
}
data1 = response1.getDataTable();
}
function handleQueryResponseTR2(response2) {
if (response2.isError()) {
alert('Error in query: ' + response2.getMessage() + ' ' + response2.getDetailedMessage());
return;
}
data2 = response2.getDataTable();
}
function handleQueryResponseTR3(response3) {
if (response3.isError()) {
alert('Error in query: ' + response3.getMessage() + ' ' + response3.getDetailedMessage());
return;
}
data3 = response3.getDataTable();
}
function drawRegionsMap() {
var query1 = new google.visualization.Query("https://docs.google.com/spreadsheets/d/14VouG7zZqHGB9CA6bxQx6CXX-TvOYkSqTmrN5DAj1Do/edit#gid=1175123524");
var query2 = new google.visualization.Query('https://docs.google.com/spreadsheets/d/1RsugJPtz2EdHOLaiL0SvR9bh61H-vAgn9x1QBjIJ--c/edit?usp=sharing');
var query3 = new google.visualization.Query('https://docs.google.com/spreadsheets/d/1zPP22gUPLDqTrvASIU3OXpmeHL_9IBS2O4z75g-1BHY/edit?usp=sharing');
query1.send(handleQueryResponseTR1);
query2.send(handleQueryResponseTR2);
query3.send(handleQueryResponseTR3);
}
请注意,在收到响应时,会异步调用handleQueryResponse函数。