Google 图表 - “缺少请求 ID 的查询:0”

发布于 2024-09-24 04:57:54 字数 2255 浏览 4 评论 0原文

仅当我尝试将两个图表放在同一页面上时才会出现此错误。如果这两个图表是页面上唯一的图表,则它们可以完美地工作。在我添加第二个的那一刻,仅加载第一个,并且出现“缺少请求 id 的查询:0”错误。
这是我的图表 js 文件:

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

往昔成烟 2024-10-01 04:57:54

可能为时已晚,但对于任何感兴趣的人来说......

从数据源加载数据时,请求中会有一个 GET 参数 - tqx - 其值如下:“reqId:0”。您必须在响应中返回相同的 reqId。

来自文档

reqId - [请求中必需;数据源必须处理] 数字
该请求的标识符。这样如果客户端发送
在收到响应之前多次请求,数据源可以
识别带有正确请求的响应。将此值发送回
响应。

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.

飘落散花 2024-10-01 04:57:54

我在 StackOverflow 中没有足够的状态来撰写评论,但这个线程也为我节省了大量时间。 谢谢

带有自己数据的 Google 可视化多个图表查询

I don't have enough status in StackOverflow to write a comment, but this thread saved me an immense amount of time as well. THANK YOU

google visualization multiple charts with own data queries

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文