2
I’m putting in a array
total sales value per month. The code is working perfectly, but I need the javascript
check which months are not in this array and fill it in order 1 to 12. For example:
The code generated an array like this:
[{4:3094}, {6:9873}, {7:6531}, {12:10937}]
Then you have the months 4, 6, 7 e 12
.
I need the code to enter the other months (1,2,3,5,8,9,10,11)
in this array with the value of 0 and leave on the order of months that are 1,2,3,4,5,6,7,8,9,10,11,12
I have the code:
var resultadosOne = {};
var highchartsOne = [];
for (ano in resultadosOne) {
var mesVendaArray = [];
for(mes in resultadosOne[ano]){
var vendaMes = 0;
resultadosOne[ano][mes].forEach((venda) => {
VendaFormatada = venda.replace(",", ".");
if(VendaFormatada <= 0){
VendaFormatada = 0;
}
vendaMes += parseFloat(VendaFormatada);
});
mesVendaArray.push({mes:mes, venda: vendaMes});
};
if(ano != ""){
highchartsOne.push({name:ano, data:mesVendaArray, color:'#6AB241'});
}
};
I’m trying to use his Method 1 and he doubles his months. For example, if you have 5 months with the sale values it takes and complete from 1 to 12 plus play +5 totaling 17.
– Alisson Acioli
@Alissonacioli Thanks for pointing, I made a small correction - test the new code.
– OnoSendai
I didn’t test if this last one of yours works, but I made a change to the line and left it like this: if (v.mes == m){ found = true; } and it worked partially, then I just had to sort with Sort() and do a function inside the Sort to sort the field month I gave it right. Thank you
– Alisson Acioli