2014-02-11 95 views
0

我有一個可以正常工作的高圖,當JS內部有script標籤時,但如果我移動到外部JavaScript,它會停止加載。 I gather我需要一個onLoad處理程序,但我對它的屬性感到困惑。示例onLoad處理程序?

這是我的HTML:

<!DOCTYPE html> 
<html> 
<head> 
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"> 

    <script type='text/javascript' src='//code.jquery.com/jquery-1.9.1.js'></script> 
    <script type='text/javascript' src="//code.highcharts.com/highcharts.js"></script> 
    <script type='text/javascript' src="//code.highcharts.com/modules/drilldown.js"></script> 
    <script type='text/javascript' src="allspending.js"></script> 


</head> 
<body> 
<div id="allspending" style="min-width: 310px; height: 400px; margin: 0 auto"></div> 

</body> 
</html> 

這是(一個嚴重簡單化的版本) 「allspending.js」:

var allspending = [ 
    [2002, 591856], 
    [2003, 839446], 
    [2004, 848463] 
]; 


$(function() { 
    $('#allspendng').highcharts({ 
     chart: { 
      type: 'column', 
      renderTo: 'allspending' 
     }, 
     series: [{ 
      data: allspending, 

     }] 
    }); 
}); 

回答

0

誠然,我還沒有玩過highchart,但我認爲jQuery的準備工作比您想要的要早。我想像,在allspending.js定義是:通過

function init() 
{ 
    $('#allspendng').highcharts({ 
     chart: { 
      type: 'column', 
      renderTo: 'allspending' 
     }, 
     series: [{ 
      data: allspending, 

     }] 
    }); 
} 

,並從onload事件調用它,例如:

<body onLoad="init()"> 

會做的伎倆。