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

188
Views
React Array TypeError: no se pueden leer las propiedades de undefined (leyendo 'longitud')

Estoy usando chart.js para crear un gráfico. Declare data: minsu importando Array llamado minsu en data .

Y de acuerdo con el valor minsu, green if greater than 100 Se crea una declaración condicional con un 'amarillo si es menor que 100' para la declaración.

Pero recibo un error con la sintaxis for (let i =0 i < dataset.data.length; i++) . TypeError: Cannot read properties of undefined (reading 'length')

Si modifico el código en la declaración condicional for, se procesará correctamente, pero no sé cómo modificar el código.

 let minsu = ProductDetail && ProductDetail.materialsInfo.map(array => array.chartPercentage) console.log(minsu); // Array [100, 50, 20, 60, 120] let chartColors = { yellow: 'rgb(244, 208, 104)', green: '#4CC26F', gray: '#EBEBEB' }; const data = { datasets: [ { backgroundColor: [], data: minsu, }, ], }; console.log(data); // Array [100, 50, 20, 60, 120] // The reference value is 100 . let colorChangeValue = 100; let dataset = data.datasets[0]; for (let i = 0; i < dataset.data.length; i++) { if (dataset.data[i] > colorChangeValue) { dataset.backgroundColor[i] = chartColors.green; if (dataset.data[i] < 100) { dataset.backgroundColor[i] = chartColors.gray; } } if (dataset.data[i] < colorChangeValue) { dataset.backgroundColor[i] = chartColors.yellow; } }
about 4 years ago · Juan Pablo Isaza
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!