-1
I am making a call via ajax and returning an array. Using the.log console I see the result of the query. But what I need to call this result inside another google Chart function
quantityDaySurgeries = function(){
var array = '';
$.ajax({
async: false,
type: "POST",
dataType: "json",
url: getUrl + 'informations/dashboard',
data: {datec:$("#datepicker_3").val(),dater:$("#datepicker_4").val() },
success: function(data) {
$.each( data.daysurgerys, function(index,element){
array += '["'+element.day+'",'+element.quantity+','+element.pen+','+element.nop+'],';
})
}
});
return array;
};
If I call her that it doesn’t come dice
function drawVisualization() {
var data = google.visualization.arrayToDataTable([
['Month', '','',''],
quantityDaySurgeries()
]);
Could someone help me? Thank you
I used your example of Promise but the return does not appear inside the Chart function, only if you give the console.log that I see the result.
– marcelo_faria
@marcelo_faria do not know how Chart works, but theoretically the process to get and work the data is this. If you run with the input data manually in the function, it works?
– Hiago Souza
I was pulling from the database and iterating php array right into it and it works normally. Ali vai ficar resultados assim ["11/11",0,0,0],["12/11",0,0,0],["13/11",3,2,1],["14/11",0,0,0],["15/11",0,0,0] .... but how I need to later make queries of different dates , I’m using javascript to not need to refresh the page for different searches and such
– marcelo_faria
@marcelo_faria updated the answer. Forehead again please.
– Hiago Souza
The way that Voce did now is returning an array for each item, it will not work like this, because it only needs to return the items separated by commas and within the brackets ["11/11",0,0],["12/11",0,0].... the previous code it returns the way it needs, only it is not displaying the data just calling the RESULT, if it calls console.log(result) it shows the data coming straight, but inside the function it does not return anything
– marcelo_faria
the problem is only being in displaying the return, the data is coming right, but it does not display inside the other function by calling it just as RESULT
– marcelo_faria
@marcelo_faria where you put the console.log?
– Hiago Souza
I put where RESULT is, then it displays the correct data, but if you take the console and leave only the RESULT does not appear the information to generate the chart
– marcelo_faria