2013-07-08 43 views
2

我想在android应用程序中加载谷歌图表。但是,它引发了我没有定义谷歌的错误。以下是我的HTML文件和JavaScript文件。未捕获的参考错误:谷歌未定义谷歌图表

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Patient Vitals</title> 

<link href="../../common/scripts/lib/css/jquery.mobile.theme-1.1.0.css" rel="stylesheet" type="text/css" /> 
<link href="../../common/scripts/lib/css/jquery.mobile-1.0.1.min.css" rel="stylesheet" type="text/css" /> 
<link rel="stylesheet" href="../../common/scripts/lib/css/jquery.mobile.datebox.css" /> 
<link href="../scripts/css.css" rel="stylesheet" type="text/css" /> 
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" /> 

<script src="../../common/scripts/jsapi.js" type="text/javascript"> 
    google.load('visualization', '1.0', {'packages':['corechart']}); 
</script> 
<script src="../scripts/patient_vitals.js"></script> 
</head> 
<body> 
     <div class="PT_Care_vitals_swa_ofcurv_left" onclick="getPatientVitalInfo();"</div> 
</body> 
</html> 

patient_vitals.js:

getPatientVitalInfo =function() 
{ 
    logInformation("Get Patient Vital Information "); 
    alert("Get Patient Vital info"); 
    //code to retieve data from database 
    drawChart(temp); 
} 

drawChart = function(temp) 
{ 
    alert("Inside drawChart function"); 
    //Convert array int DataTable 
    var data = google.visualization.arrayToDataTable(temp); 
    rowCount = data.getNumberOfRows(); 
    // Instantiate and draw our chart, passing in some options. 
    chart = new google.visualization.LineChart(document.getElementById('chart_div')); 
    var options = {'tooltip': {'trigger':'none'}, 'year': "numeric", 'month':  "numeric",'day': "numeric", 'pointSize':5}; 
    //Function to perform select operation 

    //Drawing the chart in HTML page 
    chart.draw(data, options); 
}  

这里,google.visualization.arrayToDataTable(临时)抛出这个错误。对此有何想法?如何解决它?我也试图保持.js文件中的google.Visulization。但它也不起作用。如果我从浏览器运行相同的代码,它工作正常。它与Android的问题?

回答

4

似乎有点奇怪。尝试改变

<script src="../../common/scripts/jsapi.js" type="text/javascript"> 
    google.load('visualization', '1.0', {'packages':['corechart']}); 
</script> 

<script type="text/javascript" src="https://www.google.com/jsapi"></script> 
<script type="text/javascript">google.load('visualization', '1.0', {'packages':['corechart']});</script> 

然后谷歌的对象应加载正确的。此外,您粘贴图表初始化从谷歌图表,例如,

chart = new google.visualization.LineChart(document.getElementById('chart_div')); 

但你唯一的HTML是

<div class="PT_Care_vitals_swa_ofcurv_left" onclick="getPatientVitalInfo();"</div> 

你错过了chart_div ID

相关问题