I have a AngularJS
variable that stores a whole jSON that I load, the jSON data looks like this:
{
"Products": "Pimenta Vermelha muito boa",
"Product_Code": "XXXXX",
"RTV": "Alisson Acioli",
"Regional": "Sudeste",
"Cliente": "AGRO",
"Estado": "MG",
"Pricing_Zone": "XXX",
"Quinzena": "Q2",
"New_Product_Description": "Old Product",
"Active_Ingredient": "Pimenta Vermelha",
"Familia": "Pimenta",
"Group": "Grupo do IA",
"Linha": "Albaugh",
"Devolução_Faturamento": "Faturamento",
"Dia": 10,
"mes": 1,
"ano": 2015,
"Concatenar": "",
"Crop": "22 - CROP",
"Version": "OPQ",
"Tipo_Nota": "",
"Data_Lancamento": "",
"Data_Vencimento": "",
"Prazo": "",
"Condicao_Pagamento": "",
"IGM": 1.0,
"COGS": 2.0,
"Net_Sales_VP": 1.000,
"Net_Sales": 500,
"Volume": 2,
"ICMS_Tax": 100,
"Freight": 100,
"Interest": "-",
"Receita_Invoice": 3.000,
"Preco_Lista_Invoice_a_vista": "3,9",
"Preco_a_prazo": "3,9",
"Faturamento_Lista_Invoice": 10,
"Net_Sales_Lista": 10,
"Discount": "-2%",
"Range_Capaing": "#N/D",
"Range_Capaing_2": "#N/D",
"Preco_Net_Lista_usd": "3,6",
"IGM_Lista": 2.957,
"Cambio_Dia": "2,571",
"Faturamento_rs": "R$ 1.500",
"Cambio_mes": "",
"Faturamento_usd_Financeiro": ""
}
I filter these data and insert a variable that is an array. So good, everything working.
What I have to do is create an array with some data from this jSON, like this:
/* Variáveis para gerenciar o filtro */
var GraphOne = [];
var GraphTwo = [];
/* Variáveis para inserir no Highcharts */
var HighchartsOne = [];
var HighchartsTwo = [];
$scope.filteredDados.forEach(function(arrayItem){
if(arrayItem.Condicao_Pagamento != ''){
GraphOne[arrayItem.Condicao_Pagamento] = GraphOne[arrayItem.Condicao_Pagamento] || [];
GraphOne[arrayItem.Condicao_Pagamento].push(arrayItem.Net_Sales);
}
if(arrayItem.RTV != ''){
GraphTwo[arrayItem.RTV] = GraphTwo[arrayItem.RTV] || [];
GraphTwo[arrayItem.RTV].push({netsales:arrayItem.Net_Sales, igm: arrayItem.IGM, familia: arrayItem.Familia});
}
});
In the first block it creates an array and inserts the payment terms:
if(arrayItem.Condicao_Pagamento != ''){
GraphOne[arrayItem.Condicao_Pagamento] = GraphOne[arrayItem.Condicao_Pagamento] || [];
GraphOne[arrayItem.Condicao_Pagamento].push(arrayItem.Net_Sales);
}
It inserts right. I do a console.log (GraphOne); and it returns me the right array. But in the second block that is the problem. I put console.log(GraphTwo);
and it apparently on the console gives me the result:
Array []
And after a few seconds I click on this Array[ ]
it informs me the data it has on it, which in this case is what I need. The strange thing is that when this Array[ ]
appears and I click on it immediately nothing happens, but after a few seconds, if I click again, it shows me. The bad thing is I need to read this Array
further in code, but I think the code thinks it's an empty array and does not read. The first block reads normally.
I do not know if it's because his index (GraphTwo [arrayItem.RTV]) is a name that contains spaces like Alisson Acioli , but I really do not know what it can be.