2015-01-20 132 views
0

我試圖將Google圖表添加到我的項目時出現問題。該頁面不加載或加載空白頁面。嘗試加載後,它會正確顯示頁面幾秒鐘,然後頁面變爲空白並卡住。 這是我的代碼:Google Chart不加載

<script type="text/javascript"> 

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

    // 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([ 
    ['TEST 1', 3], 
    ['TEST 2', 1], 
    ['TEST 3', 1], 
    ['TEST 4', 1], 
    ['TEST 5', 2] 
    ]); 

    // Set chart options 
    var options = {'title':'ACTIONS', 
       '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> 

這是我在應用程序

<div id="chart_div" style="width:400; height:300"></div> 
+1

您確定此代碼在body onload後運行嗎? – juvian 2015-01-20 19:24:09

+0

ypeError:無法在fb(http://liondesk.it/js/libs/jquery.dataTables.min.js:7:148) 處以HTMLTableElement讀取未定義的 屬性'offsetWidth'。 (http://liondesk.it/js/libs/jquery.dataTables.min.js:91:45) at Function.m.extend.each(http://liondesk.it/js/libs/jquery- 1.11.1.min.js:2:2973) – 2015-01-20 19:25:51

+0

該頁面試圖獲取請求,但通過後可能會有2秒頁面進入空白頁面,並顯示控制檯上的錯誤 – 2015-01-20 19:28:42

回答

0

的視圖中添加的格你加載jQuery和jQueryUI的?

<script type="text/javascript"> 
    google.load("search", "1"); 
    google.load("jquery", "1.4.2"); 
    google.load("jqueryui", "1.7.2"); 
</script> 

這裏是

<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('piechart')); 

     chart.draw(data, options); 
     } 
    </script> 
    </head> 
    <body> 
    <div id="piechart" style="width: 900px; height: 500px;"></div> 
    </body> 
</html> 

你是如何試圖加載數據的一些示例代碼(工作)?你能給我們更多的信息嗎?

+0

是的,但仍然有相同的問題:( – 2015-01-20 19:33:59