gpt4 book ai didi

javascript - 查询错误 : Invalid JSON string when Creating a Chart from a Spreadsheet? GAS

转载 作者:行者123 更新时间:2023-12-03 10:29:43 26 4
gpt4 key购买 nike

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

我想不通。我唯一更改的是电子表格 URL。其余部分直接来自文档示例。我在下面提供了所有代码。如果你们能提供任何帮助,我们将不胜感激。谢谢,布兰登

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>

<div id="EntireSite">

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

最佳答案

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

关于javascript - 查询错误 : Invalid JSON string when Creating a Chart from a Spreadsheet? GAS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29267930/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com