查询错误:从电子表格创建图表时无效的JSON字符串?加油站

时间:2015-03-25 22:44:51

标签: javascript google-apps-script google-sheets google-visualization

为什么我在查询中收到错误错误:尝试使用文档here中的Google示例脚本从电子表格创建图表时出现无效的JSON字符串?

我无法弄明白。我更改的唯一内容是电子表格网址。其余部分直接来自文档示例。我在下面提供了所有代码。你们给予的任何帮助都将不胜感激。 谢谢, 布兰登



function doGet() {
  return HtmlService.createTemplateFromFile('index')
    .evaluate()
    .setSandboxMode(HtmlService.SandboxMode.NATIVE);
};

function include(filename) {
  return HtmlService.createHtmlOutputFromFile(filename).getContent();
};






<html>
  <head>
    <!--Load the AJAX API-->
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">

      // Load the Visualization API and the controls package.
     google.load("visualization", '1', {packages:['corechart']});
google.setOnLoadCallback(drawChart);
function drawChart() {
  var query = new google.visualization.Query(
      'https://docs.google.com/a/sleschool.org/spreadsheets/d/1TRcHxsLuunRUPgn-i-h3OcVvh0TNp_VhJrNBI3ulMlA/edit#gid=0');
  query.send(handleQueryResponse);
}

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

  var data = response.getDataTable();
  var chart = new google.visualization.ColumnChart(document.getElementById('columnchart'));
  chart.draw(data, { legend: { position: 'none' } });
}
</script>

<title>Data from a Spreadsheet</title>
</head>

<body>
<span id='columnchart'></span>
</body>
</html>
&#13;
&#13;
&#13;

&#13;
&#13;
<div id="EntireSite">

  <div>
    <?!= include('Chart'); ?>
  </div>
  
&#13;
&#13;
&#13; enter image description here

1 个答案:

答案 0 :(得分:1)

HtmlService.SandboxMode.NATIVE行将其更改为HtmlService.SandboxMode.IFRAME,这样我运行您添加的文档代码就可以了。