Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Google图表(表)未显示{从另一个工作表查询}_Javascript_Google Apps Script_Google Sheets_Google Visualization - Fatal编程技术网

Javascript Google图表(表)未显示{从另一个工作表查询}

Javascript Google图表(表)未显示{从另一个工作表查询},javascript,google-apps-script,google-sheets,google-visualization,Javascript,Google Apps Script,Google Sheets,Google Visualization,我正在寻找有关这个函数的帮助,以便在我的html页面上绘制一个表 加载时,页面应显示两个图表—一个已经运行的柱形图表和一个表。这是我的代码,我计划在同一页上添加更多的表和图表 <!DOCTYPE html> <html> <head> <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script> <s

我正在寻找有关这个函数的帮助,以便在我的html页面上绘制一个表

加载时,页面应显示两个图表—一个已经运行的柱形图表和一个表。这是我的代码,我计划在同一页上添加更多的表和图表

<!DOCTYPE html>
<html>

<head>
    <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
    <script type="text/javascript">

    // Load Charts and the corechart and barchart packages. You can load as many p`enter code here`ackage as you want for your charts
       google.charts.load('current', {'packages':['corechart','table']});

    // Draw the Cells tables with this function.
       google.charts.setOnLoadCallback(drawCell1chart);

    // Draw the Cell table for men function.
       google.charts.setOnLoadCallback(drawMaleTable);

   // Callback that draws the chart.

    function drawCell1chart() {

        var queryString = encodeURIComponent('SELECT B, C LIMIT 12 OFFSET 3');

        var query = new google.visualization.Query(
            'https://docs.google.com/spreadsheets------0s/gviz/tq?sheet=Data&headers=1&tq=SELECT%20B%2C%20C%20LIMIT%2011%20OFFSET%202');

        query.send(handleSampleDataQueryResponse);
    }


    function handleSampleDataQueryResponse(response) {
        if (response.isError()) {
            alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage());
            return;
        }

        //Set options.
        var options = {title:'Cell 1 Data',
                       width:600,
                       height:300};

        var data = response.getDataTable();
        var chart = new google.visualization.ColumnChart(document.getElementById('main'));
        chart.draw(data, options);
    }

     //******** Bar: This is the one that is not diplaying....even though the code is the same as above.

     function drawMaleTable() {
         // Copy from SELECT and encode it using google encoding tool. The result will be added to the end
         // of the link below.

         var queryString = encodeURIComponent('SELECT C, D LIMIT 4 OFFSET 59');
         var query = new google.visualization.Query(
               'https://docs.google.com/spreadsheets/d/-------0s/gviz/tq?sheet=Data&headers=1&tq=SELECT%20C%2C%20D%20LIMIT%204%20OFFSET%2059');

         query.send(handleQueryResponse);
    }


    function handleQueryResponse(response) {
        if(response.isError()) {
            alert('Error in query: ' + response.getMessage() +   response.getDetailedMessage());
            return;
        }

        var dataM = response.getDataTable();
        // var formatter = new google.visualization.BarFormat({width: 120});
        // formatter.format(data, 1); // Apply formatter to second column

        var table = new  google.visualization.Table(document.getElementById('barformat_div'));
        table.draw(dataM, {allowHtml: true, showRowNumber: false, width: '100%', height: '100%'});
      }

</script>
</head>

<body>
<!--Table and divs that hold the pie charts-->
    <table class="columns">
      <tr>
        <td><div id="main" style="border: 1px solid #ccc"></div></td>

    <!-- This "barformat_div" is the one that is not displaying -->

        <td><div id="barformat_div" style="border: 1px solid #ccc"></div></td>
      </tr>
    </table>

</body>
</html>

我不确定代码的问题出在哪里,因为我正确地使用了查询函数。

尝试在同一个回调中调用这两个函数, 就像这样

google.charts.load('current', {
  callback: function () {
    drawCell1chart();
    drawMaleTable();
  },
  packages:['corechart','table']
});

删除其他语句->google.charts.setOnLoadCallback

是的,工作表是公开的谢谢你的回复,但是你的建议不起作用。啊!对不起,我太马虎了;我所说的“不工作”是指图表根本没有显示。如果按照@whitehat建议的方法,即使是我以前的图表也没有任何问题,那么您是否检查了浏览器控制台中的错误?按F12,查找控制台选项卡,如果使用IE,按F12后刷新页面是的,我做了;我留下了一个额外的括号,并修复了它,但是第二个函数的表没有显示。请用最新版本的代码更新这个问题好吗?