javascript - Google 图表 API 无法正常工作

标签 javascript android webview google-visualization

我正在尝试在 webView 中为 google chart api 加载此 html 代码。它显示图表数据但不显示图形图像。我还在 list 中允许互联网许可。 list 中是否缺少任何内容或我必须在 webview 中进行某种更改。请帮忙。

<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 piechart package.
      google.load('visualization', '1.0', {'packages':['corechart']});

      // Set a callback to run when the Google Visualization API is loaded.
      google.setOnLoadCallback(drawChart);

      // Callback that creates and populates a data table, 
      // instantiates the pie chart, passes in the data and
      // draws it.
      function drawChart() {

      // Create the data table.
      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]
      ]);

      // Set chart options
      var options = {'title':'How Much Pizza I Ate Last Night',
                     'width':400,
                     'height':300};

      // Instantiate and draw our chart, passing in some options.
      var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
      chart.draw(data, options);
    }
    </script>
  </head>

  <body>
    <!--Div that will hold the pie chart-->
    <div id="chart_div"></div>
  </body>
</html>

最佳答案

这个问题很老了,但我一直在努力在 WebView 中显示一些图表和图形,我偶然发现了这个问题。像TryTryAgain引用的dev api WebView默认不启用JavaScript,但他没有提到你可以启用它以便用户可以通过使用简单的调用与WebView中的内容进行交互设置JavaScriptEnabled();

webview.getSettings().setJavaScriptEnabled(true);

供引用:http://developer.android.com/reference/android/webkit/WebSettings.html

这对我有帮助,希望对其他人也有帮助!

关于javascript - Google 图表 API 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8757675/

相关文章:

javascript - Jasny Bootstrap 更改

javascript - 单击 Electron web View 中的元素

android - 在 Android 上的 NDK 库中使用 Clang 地址清理程序

android - java插件中的Flutter依赖

android - 如何检查android上是否启用了USB连接模式?

Javascript返回关闭值函数错误

javascript - jQuery cookie 插件 : Setting a cookie for a year and after closing browser and re-opening - the cookie is gone

android - 如何使用 Android 中的辅助功能服务访问 WebView 元素的 AccessibilityNodeInfo 的 html 内容?

android - WebView在线加载网站,离线加载本地文件

android - Android WebView 中只有一个 javascript 警报,然后它停止响应