Substitution of values

0

I'm getting an array in the variable "myObj" ([00, 12, 45, 34, 23, 34, 34, 34, 05, 42, 21, 11, 31]). And I needed to put this value in the series, ie replace the array that is there hardcoded. Type: series = [myObj, ...]

var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
  if (this.readyState == 4 && this.status == 200) {
    var myObj = JSON.parse(this.responseText); // Valor que tenho
  }
};
xmlhttp.open("GET", "api/api_get_fogo.php", true);
xmlhttp.send();

var dataSales = {
  labels: ['Jan', 'Fev', 'Mar', 'Abr', 'Mai', 'Jun', 'Jul', 'Ago', 'Set', 'Out', 'Nov', 'Dez'],
  series: [
    [00, 12, 45, 34, 23, 34, 34, 34, 05, 42, 21, 11, 31], // Onde quero substituir
    [00, 24, 36, 03, 34, 10, 15, 20, 48, 19, 49, 32, 02]
  ] 
};
    
asked by anonymous 07.06.2018 / 12:11

1 answer

1

I do not know if I understood the problem well, but the instruction:

dataSales.series[0] = myObj;

Does not work?

If you want to add instead of replace you can also use push:

dataSales.series.push(myObj);
    
07.06.2018 / 12:37