Google图表无法在Android webview中使用

时间:2012-05-24 08:36:57

标签: android webview google-visualization

我在Android上使用谷歌图表。我能够在基于桌面的Web浏览器上获得所需的输出,但是当我使用android webview执行相同时,不会显示任何事情。 这是我的html和android webview的代码,我错过了什么吗?

WebView webview = (WebView) this.findViewById(R.id.webView1);

        WebSettings webSettings = webview.getSettings();

        webSettings.setJavaScriptEnabled(true);

        webSettings.setBuiltInZoomControls(true);

        webview.requestFocusFromTouch();

        webview.setWebViewClient(new WebViewClient());

        webview.setWebChromeClient(new WebChromeClient());





        // Load the URL

        webview.loadUrl("file:///android_asset/www/rG.html");

?///////////////////////////////////////////////////////////////////
for html

<html>
  <head>
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
      google.load("visualization", "1", {packages:["corechart"]});
      google.setOnLoadCallback(drawChart);
      function drawChart() {
        var data = google.visualization.arrayToDataTable([
          ['Task', 'Hours per Day'],
          ['Work',     11],
          ['Eat',      2],
          ['Commute',  2],
          ['Watch TV', 2],
          ['Sleep',    7]
        ]);

        var options = {
          title: 'My Daily Activities'
        };

        var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
        chart.draw(data, options);
      }
    </script>
  </head>
  <body>
    <div id="chart_div" style="width: 900px; height: 500px;"></div>
  </body>
</html>

1 个答案:

答案 0 :(得分:1)

你应该加载css&amp;来自本地的javascript。即"<html><head><link type=\"text/css\" rel=\"stylesheet\" href=\"file:///android_asset/styles.css\"><script type=\"text/javascript\" src=\"file:///android_asset/script.js\"></script></head><body>";