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

189
Views
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
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!