简体   繁体   中英

Error in query: Invalid JSON string when Creating a Chart from a Spreadsheet? GAS

Why am I getting the error Error in query: Invalid JSON string when attempting to create a chart from a spreadsheet using the Google example script from their documentation here ?

I can't figure it out. The only thing that I changed is the spreadsheet URL. The rest is directly from the documentation example. I provided all of my code below. Any help you guys could give would be greatly appreciated. Thanks, Brandon

 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> 
在此处输入图片说明

HtmlService.SandboxMode.NATIVE更改为HtmlService.SandboxMode.IFRAME ,这样它对我来说可以运行您添加的文档的代码。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM