7

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?

Chris
  • 1,418
  • 2
  • 16
  • 34

2 Answers2

12

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.

André Morujão
  • 6,963
  • 6
  • 31
  • 41
  • 1
    I realize this is old but wanted to write to say that this helped me immensely and lead me to realize an otherwise undebuggable issue with my use of the gviz python library. Thank you!! – mszaro Aug 02 '12 at 19:25
0

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

Community
  • 1
  • 1
Buzzy Hopewell
  • 165
  • 4
  • 14
  • You're more than welcome to ask and answer question here, you'd soon earn enough rep to leave comments (although "thank you" is not a good comment - you should just vote up good answers) – Leeor Oct 27 '13 at 16:36
  • Thanks but I'm not "old enough" to vote in StackOverflow either! In addition to saying "thank you" I did leave a link to my issue that this issue solved. – Buzzy Hopewell Oct 27 '13 at 16:53
  • Now you are, have fun :) – Leeor Oct 27 '13 at 16:58