谷歌图表 - “缺少查询请求ID:0”

问题描述:

只有当我尝试将两个图表放在同一页面上时才会出现此错误。如果这两个图表是唯一一个在页面上,则它们都能很好地工作。我添加第二个只有第一个加载和我得到“缺少查询请求ID:0”错误。
下面是我的图表js文件:谷歌图表 - “缺少查询请求ID:0”

function drawChart(title, queryPage, divToFill) { 
var dataTab = null; 
var query = new google.visualization.Query(queryPage); 
var strSQL = "SELECT *"; 

query.setQuery(strSQL); 

query.send(processInitalCall); 

function processInitalCall(res) { 
    if(res.isError()) { 
     alert(res.getDetailedMessage()); 
    } else { 
     dataTab = res.getDataTable(); 

     // Draw chart with my DataTab 
     drawChart(dataTab); 
    } 
} 

function drawChart(dataTable) { 
    // Draw the chart 
    var options = {}; 
    options['title'] = title; 
    options['backgroundColor'] = "#8D662F"; 
    var colors = Array(); 
    var x = 0; 
    if(currentCampaignId >= 0) { 
     while(x < dataTab.getNumberOfColumns() - 2) { 
      colors[x] = '#c3c1b1'; 
      x++; 
     } 
     colors[x] = '#d2bc01'; 
    } 
    else { 
     colors[0] = '#c3c1b1'; 
    } 
    options['colors'] = colors; 
    options['hAxis'] = {title: "Week", titleColor: "white", textColor: "white"}; 
    options['vAxis'] = {title: "Flow", titleColor: "white", textColor: "white", baselineColor: "#937d5f", gridColor: "#937d5f"}; 
    options['titleColor'] = "white"; 
    options['legend'] = "none"; 
    options['lineWidth'] = 1; 
    options['pointSize'] = 3; 
    options['width'] = 600; 
    options['height'] = 300; 
    var line = new google.visualization.LineChart(document.getElementById(divToFill)); 
    line.draw(dataTab, options); 
} 
} 

这里是index.php文件,可谓物美价廉:

<body> 
<script type="text/javascript"> 
google.load('visualization', '1', {'packages': ['table', 'corechart']}); 
google.setOnLoadCallback(function(){ 
drawChart("Water", "waterData.php", "water"); 
drawChart("Air", "airData.php", "air"); 
}); 

</script> 
<div id="water" style="text-align: center;"></div> 
<div id="air" style="text-align: center;"></div> 
</body> 

它引发错误就在query.send(processInitalCall);线,仅在第二它被称为时间。除了sig字段外,waterData.php和airData.php都是相同的。我注意到有一个字段叫做reqId,它被设置为0.

我需要以某种方式在这些类中更改这个reqId吗?

可能为时已晚,但对任何有兴趣...

当从数据源加载数据,将有在请求一个GET参数 - tqx - 与像一个值:“REQID:0 ”。您必须在您的回复中返回相同的reqId。

the docs

REQID - [必需在请求;数据源必须处理]此请求的数字标识符 。这用于如果客户端在收到响应之前发送多个请求 ,则数据源可以使用 标识具有正确请求的响应。将此值发送回 的回应。

+0

我得到这个错误,我REQID匹配。 – 2011-10-10 18:07:45

+1

我意识到这是古老的,但想写信说这对我有着巨大的帮助,并导致我意识到我使用gviz python库时出现了其他不可解码的问题。谢谢!! – mszaro 2012-08-02 19:25:54

我没有足够的状态在*中编写评论,但是这个线程也为我节省了大量的时间。 THANK YOU

google visualization multiple charts with own data queries

+0

您不仅欢迎您在这里提问和回答问题,您很快就会获得足够的代表发表评论(尽管“谢谢”不是一个好评 - 你应该只是投了个好答案) – Leeor 2013-10-27 16:36:10

+0

谢谢,但我是不是“足够老”来投票在*中!除了说“谢谢”之外,我确实给我的问题留下了一个链接,解决了这个问题。 – 2013-10-27 16:53:52

+0

现在你是,玩得开心:) – Leeor 2013-10-27 16:58:46