本文介绍了未捕获错误:未定义容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用Google图表生成甘特图,然后根据现有的PHP代码编码,我得到一个空白的HTML。请帮助我,以便成功显示图表。

  <html>
  <head>
    <!--Load the AJAX API-->
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <script type="text/javascript">

    // Load the Visualization API and the gantt chart package.
     google.load("visualization", "1", {packages: ["timeline"]});

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

    function drawChart() {
       $.ajax({
      url: "http://localhost:8080/index1.php",
      dataType:"json",
      async: false ,
      success: function(data) {
           jsonData = data;
         }
          });

      // Create our data table out of JSON data loaded from server.
      var data = new google.visualization.DataTable(jsonData);

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

    </script>
  </head>

  <body>
    <div id="chart_div" style="width: 900px; height: 200px;></div>
  </body>
</html>


推荐答案



You are missing : " on the div style

<div id="chart_div" style="width: 900px; height: 200px;></div>

未定义 div ,因此JS无法找到它

The div is not defined, so the JS cant find it.

getElementById 失败。

这篇关于未捕获错误:未定义容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-27 19:15
查看更多