谷歌图表 - “缺少查询请求ID:0” [英] Google Charts - "Missing Query for request id: 0"

查看:70
本文介绍了谷歌图表 - “缺少查询请求ID:0”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我尝试将两个图表放在同一页面上,则只会显示此错误。如果这两个图表是唯一一个在页面上,则它们都能很好地工作。我添加的第二个只有第一个加载,并得到缺少请求ID:0的查询错误。

这是我的图表js文件:

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

query.setQuery(strSQL);

query.send(processInitalCall);

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

//用我的DataTab绘制图表
drawChart(dataTab);



函数drawChart(dataTable){
//绘制图表
var options = {};
options ['title'] = title;
options ['backgroundColor'] =#8D662F;
var colors = Array();
var x = 0;
if(currentCampaignId> = 0){
while(x colors [x] ='#c3c1b1';
x ++;
}
colors [x] ='#d2bc01';
}
else {
colors [0] ='#c3c1b1';
}
选项['颜色'] =颜色;
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'] =无;
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);




$ b $ p $这些是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,空气);
});

< / script>
< div id =waterstyle =text-align:center;>< / div>
< div id =airstyle =text-align:center;>< / div>
< / body>

它在 query.send(processInitalCall); 行,仅在第二次调用它时使用。除了 sig 字段外,waterData.php和airData.php都是相同的。我注意到有一个名为 reqId 的字段,它设置为0。



我是否需要以某种方式更改此项 reqId 在这些类中

解决方案

可能太晚了,但对于任何人...

当从数据源加载数据时,请求中会有一个GET参数 - tqx - 具有类似于:reqId:0。您必须在回复中返回相同的reqId。



文档


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



This error only appears if I try to put two charts on the same page. Both charts work perfectly if they are the only one on the page. The minute I add the second only the first one loads and I get the "Missing Query for request id: 0" error.
Here is my js file for the chart:

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);
}
}  

Here is a snip from the index.php file:

<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>  

It throws the error right at the query.send(processInitalCall); line, only on the second time it's called. Both the waterData.php and airData.php are identical except for the sig field. I did notice there was a field called reqId and it's set to 0.

Do I need to somehow change this reqId in these classes?

解决方案

Probably too late, but for anyone interested...

When loading data from the data source, there will be a GET parameter in the request - tqx - with a value like: "reqId:0". You must return the same reqId in your response.

From the docs:

reqId - [Required in request; Data source must handle] A numeric identifier for this request. This is used so that if a client sends multiple requests before receiving a response, the data source can identify the response with the proper request. Send this value back in the response.

这篇关于谷歌图表 - “缺少查询请求ID:0”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆