Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

75
Views
No puedo mapear elementos de una matriz.

Estoy tratando de recibir los datos de mi API en los gráficos de mi sitio web. Estoy atascado tratando de llenar mis gráficos con los datos, tengo el código para completar los gráficos, pero cuando mapeo los datos JSON e intento dividir los datos en Fecha y temperatura para ponerlos en el gráfico, simplemente no funciona.

Este es el código:

 var xmlhttp = new XMLHttpRequest(); var url = "http://localhost:8090/api/grafico/datos/temperatura/medicionAire/2059"; xmlhttp.open("GET", url, true); xmlhttp.send(); xmlhttp.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { var data = JSON.parse(this.responseText); //console.log(data); var dateG = data.map(function(elem) { return elem.fecha; }); var temperatureG = data.map(function(elem) { return elem.temperatura; }); } }

Intenté depurarlo y parece que no reconoce "fecha" o "temperatura" dentro de la matriz, aunque "elem" tiene la matriz: como puede ver en esta imagen, "elem" tiene la matriz, pero "elem.fecha" no está definido y no sé por qué. Debería devolverme una matriz con solo "fecha" de cada línea.

ingrese la descripción de la imagen aquí

Registro de salida de datos:

 [Array(4)] 0: Array(4) 0: {fecha: '2021-09-03T13:15:41.943Z', temperatura: 22.33} 1: {fecha: '2021-09-03T13:15:41.230Z', temperatura: 22.33} 2: {fecha: '2021-09-03T13:15:04.243Z', temperatura: 22.33} 3: {fecha: '2021-09-03T13:14:06.923Z', temperatura: 16.56} length: 4 [[Prototype]]: Array(0) length: 1 [[Prototype]]: Array(0)
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Creo que si tuviera que modificar su código en algo así:

 var dateG = data.map(function(elem) { return elem.map(function(innerElem) { return innerElem.fecha }); });

Terminaría con dateG como una matriz 2D de valores de búsqueda.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!