자바 스크립트를 사용하는 그래프 library을 사용하고 있습니다. 다른 Ajax 스크립트로 데이터를 가져온 후에이 스크립트를 실행해야합니다. 내가 스크립트를 사용할 때아약스 게시 함수 호출 함수
var request, response;
var newUrl = url + '/thermometer/getLastHourData';
var data = $.ajax({
url: newUrl,
data: request,
dataType: "json",
method: "post",
success: function(data) {
drawGraph();
return data;
},
error: function() {
alert('Error occured');
}
});
또한 drawGraph 기능은
google.load("visualization", "1");
// Set callback to run when API is loaded
google.setOnLoadCallback(drawVisualization);
// Called when the Visualization API is loaded.
function drawVisualization() {
// Create and populate a data table.
var data = new google.visualization.DataTable();
data.addColumn('datetime', 'time');
data.addColumn('number', 'Function A');
data.addColumn('number', 'Function B');
function functionA(x) {
return Math.sin(x/25) * Math.cos(x/25) * 50 + (Math.random()-0.5) * 10;
}
function functionB(x) {
return Math.sin(x/50) *50 + Math.cos(x/7) * 75 + (Math.random()-0.5) * 20 + 20;
}
// create data
var d = new Date(2010, 9, 23, 20, 0, 0);
for (var i = 0; i < 100; i++) {
data.addRow([new Date(d), functionA(i), functionB(i)]);
d.setMinutes(d.getMinutes() + 1);
}
// specify options
var options = {
"width": "100%",
"height": "350px"
};
// Instantiate our graph object.
var graph = new links.Graph(document.getElementById('mygraph'));
// Draw our graph with the created data and options
graph.draw(data, options);
}
이
drawGraph에 시작 (내가 코드를 확인하기 때문에 제대로 실행에 필요한 변경하지 않았다)이다 일부 라이브러리에서는 google.com을로드 할 때까지 기다리지 만 ajax 함수를 호출하지 않고 drawGraph 함수를 사용하면 처음부터 언급 한 링크 에서처럼 작동합니다.
아약스에서이 그래프 함수를 문제없이 어떻게 호출 할 수 있습니까?
당신은'drawGraph();'대신'google.load ("visualization", "1"); – Cristian
예. 시도했습니다. 또한 주요 문제는 해당 기능을 호출하는 것입니다. – irukeru