Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

187
Visualizações
Uncaught (in promise) Typerror, undefined variable, but in console.log the object is displayed

This seems to be a promise error but when I console.log in my Chart class it works fine. Here is the relevant part of the Chart class:

createScales(){
    console.log(this.data); //this works fine, data is type 'object'.
    this.keynames = d3.scaleOrdinal();

    this.keynames.domain(Object.keys(this.data[0]).filter(function(key){
      console.log(key); //this works fine too, column keys are returned.
      return key !== 'date';
    }));

    this.keymap = this.keynames.domain().map(function(keyname) {
      return{
        name: keyname,
        values: this.data.map(function(d){ //here is the error
          return {
            date: d.date,
            key: +d[keyname]
          }
        })
      }
    });

I'm new to javascript and some terminology is still unfamiliar to me. Why is data undefined inside this.keymap but works just fine when logged outside?

This is the full traceback:

chart.js:46 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'data')
    at chart.js:46
    at Array.map (<anonymous>)
    at Chart.createScales (chart.js:43)
    at Chart.draw (chart.js:30)
    at Chart.setData (chart.js:116)
    at init (plot.js:15)
(anonymous) @ chart.js:46
createScales @ chart.js:43
draw @ chart.js:30
setData @ chart.js:116
init @ plot.js:15
Promise.then (async)
(anonymous) @ plot.js:12

This is how I'm passing my data to chart.js:

let getData = d3.csv('d1.csv', function(d){
                        //data returning stuff here, works fine 
                        }
                      }).then(init);

function init(data){
  chart.setData(data); //updates constructor with new data
}

As I previously stated, my data works fine when read from the Chart class. Does anyone know what's going on?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda