Google可视化多重查询(电子表格)

时间:2014-08-21 07:44:20

标签: javascript charts google-visualization

我必须在HTML页面上显示多个图表,但我无法进行多次查询(直接在Google spreedsheet上)。

实际上,我只有第一个显示的查询。

我的代码:

<html>
<head>
<meta charset="utf-8">
<title>Page de pilotage</title>
<link rel=stylesheet type="text/css" href="style.css">
<script type="text/javascript" src="javascript.js"></script>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
  google.load("visualization", '1', {packages:['corechart']});
  google.setOnLoadCallback(drawChart);
  function drawChart() {
    var query = new google.visualization.Query('https://docs.google.com/spreadsheets/d/xxx/gviz/tq?sheet=visites');
    var query2 = new google.visualization.Query('https://docs.google.com/spreadsheets/d/xxx/gviz/tq?sheet=transactions');
    query.send(handleQueryResponse);
    query2.send(handleQueryResponse);
  }

  function handleQueryResponse(response) {

  var options = {
  pointSize: 4,
  title: '',
  }

  var data = response.getDataTable();
  var chart = new google.visualization.LineChart(document.getElementById('visites'));
  var chart2 = new google.visualization.LineChart(document.getElementById('transactions'));
  chart.draw(data, options);
  chart2.draw(data, options);
  }
</script>
</head>

<body>
<h1>Page de pilotage - KPI/PROGRESSION</h1>
<p>Cette page WEB rassemble des informations générales pour aider au pilotage du site</p>

<h2>PROGRESSION</h2>

<div style="width:1200px;">

  <div style="width:599px; float:left;">
  <h3>NOMBRE DE VISITES</h3>
  <div id="visites" style="height: 280px; z-index: 1; margin-top: -25px; border-right:1px solid #ccc;"></div>
</div>

  <div style="width:599px; float:right;">
  <h3>NOMBRE DE TRANSACTIONS</h3>
  <div id="transactions" style="height: 280px; z-index: 1; margin-top: -25px;"></div>
  </div>

</div>

</body>
</html>

我认为问题出在以下几个方面:

query.send(handleQueryResponse);
query2.send(handleQueryResponse);

1 个答案:

答案 0 :(得分:1)

  function drawChart() {
    var visites = new google.visualization.Query('https://docs.google.com/spreadsheets/d/xxx/gviz/tq?sheet=visites');
    var transactions = new google.visualization.Query('https://docs.google.com/spreadsheets/d/xxx/gviz/tq?sheet=transactions');
    visites.send(handleQueryResponse);
    transactions.send(handleQueryResponse2);
    conversion.send(handleQueryResponse3);
    rebond.send(handleQueryResponse4);
  }

  function handleQueryResponse(response) {

          var options = {
                  pointSize: 4,
                  title: '',
          }

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

  function handleQueryResponse2(response) {

          var options = {
                  pointSize: 4,
                  title: '',
          }

          var data = response.getDataTable();
          var chart2 = new google.visualization.LineChart(document.getElementById('transactions'));
          chart2.draw(data, options);
  }