0
I’m making a request to plot a chart using Flot Js.
I’m returning a Json like this:
[{
"status": "Finalizado",
"id_status": "4",
"total_chamado": "2",
"mes": "4",
"ano": "2015"
}, {
"status": "Finalizado",
"id_status": "4",
"total_chamado": "1",
"mes": "5",
"ano": "2015"
}, {
"status": "Finalizado",
"id_status": "4",
"total_chamado": "1",
"mes": "6",
"ano": "2015"
}, {
"status": "Finalizado",
"id_status": "4",
"total_chamado": "1",
"mes": "7",
"ano": "2015"
}, {
"status": "Em Aberto",
"id_status": "1",
"total_chamado": "1",
"mes": "8",
"ano": "2015"
}, {
"status": "Finalizado",
"id_status": "4",
"total_chamado": "1",
"mes": "8",
"ano": "2015"
}, {
"status": "Em Aberto",
"id_status": "1",
"total_chamado": "3",
"mes": "9",
"ano": "2015"
}, {
"status": "Em Aberto",
"id_status": "1",
"total_chamado": "1",
"mes": "10",
"ano": "2015"
}, {
"status": "Em Aberto",
"id_status": "1",
"total_chamado": "1",
"mes": "11",
"ano": "2015"
}]
And I need that in Javascript he stays that way:
vetor = [ [mes, total], [mes, total], [mes, total], [mes, total], [mes, total], [mes, total] ];
I’m trying like this, but it’s not working. The graph doesn’t mount.
var caixa_entrada = []
$.ajax({
type: "GET",
cache: false,
url: baseURL + '/dashboard/grafico-chamado',
dataType: 'json',
success: function(data){
$.each(data, function(index, value){
caixa_entrada.push([index, value.total_chamado]);
});
}
});
I did a test here (apart from the ajax part) and the loop seems to work, assembling a multidimensional array. Is there no problem in some other part of the code?
– Bacco
Oh my... I know what it is! But I don’t remember how to solve it. The variable is inside a
callback
. Like I’m taking her out ?– Diego Souza
yeah, could be scope problem even.
– Bacco
Solved. I put
async: false
in options.– Diego Souza
Glad you solved it. I’ll delete my comments here.
– Bacco