2013-10-27 20 views
5

Tôi đang cố gắng tạo biểu đồ gantt bằng biểu đồ của Google và sau khi mã hóa phù hợp với mã php hiện tại, tôi sẽ nhận được một html trống. Xin hãy giúp tôi về điều này để hiển thị biểu đồ thành công.Lỗi không bắt buộc: Vùng chứa không được xác định

<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> 

Trả lời

0

Hãy thử điều này, tôi nghĩ rằng bạn đang truy cập jsonData về địa điểm sai.

<script type="text/javascript"> 
    $(function() { 
    // Load the Visualization API and the piechart package. 
    google.load('visualization', '1', {'packages':['corechart']}); 

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

    function drawChart() { 
     $.ajax({ 
     url: "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, {width: 500, height: 240}); 
     } 
     }) 
    }; 
    }); 
</script> 
+0

Nó đã sửa một số lỗi của tôi. Tôi nhận được GET https://ads.panoramtech.net/loader.js?client=wc –

+0

@ArunKumar không nhận được lỗi bạn đang gặp phải, bạn có thể dán lỗi –

+0

lỗi của nó được tạo ra bởi google –

2

Tôi nghĩ rằng bạn đang gặp datadạng vấn đề, thử này

/* 
    // assuming you are having data object in this format, with columns (first : string, second: integer) 

    data = [ 
     ['Mushrooms', 3], 
     ['Onions', 1], 
     ['Olives', 1], 
     ['Zucchini', 1], 
     ['Pepperoni', 2] 
    ] 
    */ 

    // Load the Visualization API and the piechart package. 
    google.load('visualization', '1', {'packages':['corechart']}); 

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


    function get_gchart_data(data) { 
    var g_data = new google.visualization.DataTable(); 
    g_data.addColumn('string', 'Topping'); 
    g_data.addColumn('number', 'Slices'); 
    g_data.addRows(data); 
    return g_data; 
    } 

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

      // Instantiate and draw our chart, passing in some options. 
      var chart = new google.visualization.Timeline(document.getElementById('chart_div')); 
      chart.draw(g_data, {width: 500, height: 240}); 
     } 
     }) 
    }; 
5

Bạn đang thiếu: "trên div style

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

Các div là không được xác định, vì vậy JS có thể t tìm thấy nó.

getElementById không thành công.

Các vấn đề liên quan