Google Visualization not working with appscript html service
Asked Answered
S

2

5

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.

Sapling answered 24/7, 2012 at 6:53 Comment(1)
For others arriving at this question the Google Visualisation API should be fully accessible using the IFRAME sandbox mode in HtmlServiceSpinthariscope
U
7

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

  1. Copy your HTML file code to "Source" Tab at Caja Playground
  2. Hit Cajole button
  3. After some time, Rendered result Tab will show you the result

You may report this issue in Caja issue Tracker

Unpredictable answered 24/7, 2012 at 8:7 Comment(0)
K
2

Waqar is correct, but visualization support is coming.

Kila answered 24/7, 2012 at 12:40 Comment(2)
Good to know that. Waiting eagerly for that featureUnpredictable
I look forward to that support.Nakano

© 2022 - 2024 — McMap. All rights reserved.