Google visualization does not work with support for httml applications

I want to use appscript htmlservice along with appscript. The html service is working, but the rendering is not working. 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 the world of Hello was published, but there are no signs of a graph.

+5
source share
2 answers

The HtmlService uses Caja to filter unsafe Javascript, CSS, and html from its HTML page, and then displays the contents of the file in a browser. When I tested your code on the Caja playground, it shows the same behavior, so this is a problem with Caja and not with Htmlservice. You can check your HTML file on Caja Payground

HTML

Caja issue Tracker

+7

, .

+2

All Articles