小编Moa*_*pra的帖子

谷歌图表外部Javascript问题

我的问题是,当我把任何谷歌图表的js代码放在外部javascript文件中时.它开始加载页面并且不显示任何东西.如果内联javascripts其工作正常.

以下是我的HTML代码"google barchart.html"

 <html>
     <head>
       <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />    
       <script type="text/javascript" src="jquery.js"></script>
       <script type="text/javascript" src="https://www.google.com/jsapi"></script>
       <script type="text/javascript" src="test.js"></script>
       <script type="text/javascript"></script>
    </head>
    <body>
      <input type="button" id="btn" value="Show Graph" />
      <div id="chart_div" style="width: 441px; height: 300px;"></div>
    </body>
 </html>
Run Code Online (Sandbox Code Playgroud)

这是我的js文件"test.js"

 $(document).ready(function()  {    $('#btn').click(function()      {   //alert("hi");
       google.load("visualization", "1", {packages:["corechart"]});
      google.setOnLoadCallback(drawChart);
      function drawChart() {
        var data = google.visualization.arrayToDataTable([
          ['', 'Your Restaurant', 'Other Restaurants'],
          ['Question1',  5, 4],
          ['Question2',  4, 5],
          ['Question3',  3, 2],
          ['Question4',  5, 1]
        ]);

        var options = {
          //title: 'Company Performance',
          hAxis: …
Run Code Online (Sandbox Code Playgroud)

javascript charts external

4
推荐指数
1
解决办法
4896
查看次数

标签 统计

charts ×1

external ×1

javascript ×1