Google可视化不能与appscript html服务一起使用 [英] Google Visualization not working with appscript html service
问题描述
我想使用appscript htmlservice以及appscript,
html服务似乎可行,但可视化不起作用。
这里是供参考的代码。
Code.GS:
//脚本作为应用程序模板。
函数doGet(){
return HtmlService.createHtmlOutputFromFile('html_visualization');
}
html_visualization.html
< html>
< head>
< script type =text / javascriptsrc =https://www.google.com/jsapi>< / script>
< script type =text / javascript>
google.load('visualization','1.0',{'packages':['corechart']});
google.setOnLoadCallback(drawChart);
函数drawChart(){
var data = new google.visualization.DataTable();
data.addColumn('string','Topping');
data.addColumn('number','Slices');
data.addRows([
['Mushrooms',3],
['Onions',1],
['Olives',1],
[ '西葫芦',1],
['Pepperoni',2]
]);
var options = {'title':'我昨晚吃了多少披萨','宽度':400,'height':300};
var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
chart.draw(data,options);
}
< / script>
< / head>
< body>
< div id =chart_div>< / div>
Hello World
< / body>
< / html>
发布时出现Hello world,但没有图表的符号。
< HtmlService使用Caja从HTML页面中过滤不安全的Javascript,CSS和html,然后将文件内容呈现给浏览器。
当我在Caja操场上测试你的代码时,它显示了相同的行为,所以这是Caja而不是Htmlservice的问题。
您可以在 Caja Payground 上测试您的Html文件
测试HTML文件的步骤
- 将您的HTML文件代码复制到 Caja游乐场
- 点击Cajole按钮
- 一段时间后,渲染结果标签会显示结果
您可以在 Caja问题跟踪器
I want to use appscript htmlservice along with appscript, The html service seems to work but the visualization do not work. Here is the code for reference. Code.GS :
// Script-as-app template.
function doGet() {
return HtmlService.createHtmlOutputFromFile('html_visualization');
}
html_visualization.html
<html>
<head>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load('visualization', '1.0', {'packages':['corechart']});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'Topping');
data.addColumn('number', 'Slices');
data.addRows([
['Mushrooms', 3],
['Onions', 1],
['Olives', 1],
['Zucchini', 1],
['Pepperoni', 2]
]);
var options = {'title':'How Much Pizza I Ate Last Night','width':400, 'height':300};
var chart = new google.visualization.PieChart(document.getElementById ('chart_div') );
chart.draw(data, options);
}
</script>
</head>
<body>
<div id="chart_div"></div>
Hello World
</body>
</html>
When published Hello world appears but no sign of the chart.
HtmlService uses Caja to filter the unsafe Javascript, CSS and html from your HTML page and then it renders the filetered content to the browser. As I tested your code at Caja playground, It shows same behavior, so this is the issue with Caja, not Htmlservice. You may test your Html file at Caja Payground
Steps to test your HTML file
- Copy your HTML file code to "Source" Tab at Caja Playground
- Hit Cajole button
- After some time, Rendered result Tab will show you the result
You may report this issue in Caja issue Tracker
这篇关于Google可视化不能与appscript html服务一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!