2012-08-02 28 views
0

正如你可能会看到下面,我创建了函数getChart(); 它在自己调用时工作,但是当我将它包装到$(document).ready(function(){...})时不显示图表; 我还附上了文件.. 任何帮助,高度重视和感激..感谢名单..谷歌图形不工作与jQuery按钮功能

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
    <meta http-equiv="content-type" content="text/html; charset=utf-8" /> 
    <title>Google Visualization API Sample</title> 
    <script type="text/javascript" src="http://www.google.com/jsapi"></script> 
    <script type="text/javascript" src="jquery.js"></script> 
    <script type="text/javascript"> 

    function getChart(){ 
    google.load('visualization', '1', {packages: ['corechart']}); 
    function drawVisualization() { 
     // Populate the data table. 

     var dataTable = google.visualization.arrayToDataTable([ 
      ['Mon', 20, 28, 38, 45], 
      ['Fri', 68, 66, 22, 15] 
     // Treat first row as data as well. 
     ], true); 

     // Draw the chart. 
     var chart = new  google.visualization.CandlestickChart(document.getElementById('visualization')); 
     chart.draw(dataTable, {legend:'none', width:600, height:400}); 
    } 

    google.setOnLoadCallback(drawVisualization); 

    } 

    $(document).ready(function(){ 
     $('#idbutton').click(function(){ 
      getChart(); 
     }); 
    }); 


    </script> 
</head> 
<body> 
<input id="idbutton" type="button" value="button" /> 
<div id="visualization"></div> 
</body> 
</html> 
+0

'getChart()'返回一个字符串吗?做alert(getChart());'告诉我们输出。 – 2012-08-02 16:52:31

+0

如果我不得不猜测,我猜“这个”并不是指向你想要的地方,但说实话,这里没有太多的代码。 – tsiki 2012-08-02 18:09:17

+0

我附上了上面的代码..谢谢.. – MegaByteMe 2012-08-02 19:55:35

回答

0

尝试将其附加到window对象。 喜欢的东西

$(document).ready(function(){ 
    window.getChart = function() { //Code of getChart here }; 
}); 

里调用:

$(document).ready(function(){ 
    $('#idbutton').click(function(){ 
     window.getChart(); 
    }); 
}); 

注:我没有测试它。

+0

我已经尝试过了..但它似乎没有使用任何jQuery方法.. – MegaByteMe 2012-08-02 20:12:22

+0

让我感到困惑的是,当我调用getChart();函数在它自己的工作,我可以显示图表..但我真的需要的是将该功能附加到事件监听器..基本上,我得到了101股票表,我希望能够显示各个图表动态,当我点击一行..该按钮仅用于测试目的。我会非常欢迎其他建议.. – MegaByteMe 2012-08-02 20:21:10

+0

这很奇怪。当你在不使用jquery函数的情况下对jquery进行测试时,是否包含对jquery的引用? – Vertigo 2012-08-04 14:59:08