I am using a graph library which is using javascript. I have to run this script after getting the data with another ajax script. But when I use the script
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');
}
});
Also the drawGraph function is
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);
}
(I did not change it what I need to since checking the code is running correctly)
drawGraph start to wait for loading google.com for some library but when I use the function drawGraph without calling from the ajax function, it works as in the link that I mention at the begining.
How can I call this graph function from ajax without problem ?