0
我寫了一個代碼來調用服務器的數據,並使用谷歌圖表以圖表的形式顯示數據。 我面臨的問題是,圖表填充後,我點擊刷新按鈕,但第一次圖表結構顯示,但數據不可見。谷歌圖表顯示數據後,我刷新瀏覽器
我使用下面的代碼 UNITY //警報( 「這裏」);
//google.load("visualization", "1", {packages:["corechart"]});
//google.setOnLoadCallback(drawChart);
var optionsx = {packages: ['corechart'], callback : drawChart};
google.load('visualization', '1', optionsx);
var queryObject="";
var queryObjectLen="";
var queryObject1="";
var queryObjectLen1="";
$.ajax({
type : 'POST',
url : 'chart.jsp',
dataType:'json',
//async : false
success : function(data) {
queryObject = eval('(' + JSON.stringify(data) + ')');
queryObjectLen = queryObject.empdetails.length;
// document.getElementById("demo").innerHTML = queryObject.empdetails[1].CI + " " + queryObject.empdetails[1].TR;
//System.out.println(+queryObjectLen);
console.log(+ queryObject);
console.log('lenth :' +queryObjectLen);
alert('success')
},
error : function(xhr, type) {
alert('server error occured')
}
});
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'CI');
data.addColumn('number', 'Tickets Raised');
for(var i=0;i<queryObjectLen;i++)
{
var name = queryObject.empdetails[i].CI;
var NOR = queryObject.empdetails[i].TR;
data.addRows([
[name,parseInt(NOR)]
]);
}
var options = {
title: 'Number Of Unity Tickets in a week',
'width' : 500,
'height' : 300
};
變種圖表=新google.visualization.BarChart(的document.getElementById( 'chart_div'));
chart.draw(data,options);
</script>
</head>
<body>
<div id="chart_div" ></div>
<div class = "center" id="chart_div1" ></div>
<div class = "right" id="chart_div2" ></div>
<p id="demo"></p>
</body>
</html>