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

190
Views
D3 reading promise data into a constructor
const chart = new Chart({
  element: document.querySelector('#graph'),
  data: d3.csv('d1.csv', function(d){
                          function removeNaN(e,c){
                            if (e>0) {return e} else {return c}
                          }
                          return { date: d3.timeParse("%Y-%m-%d")(d.Date),
                                   aapl : d.AAPL, tsla : d.TSLA,
                                   aapl_sma: removeNaN(+d.SMA_AAPL,d.AAPL),
                                   tsla_sma: removeNaN(+d.SMA_TSLA,d.TSLA)
                          }
                        }).then(function(data){return data})
});

Hello- this is how I'm initializing my Chart() object. then() returns a Promise object that I would like to access. [[PromiseResult]] contains the data array I'd like to use. How do I access the array, and should it be done from within the Chart() class, or from the chart object?

This is the constructor:

class Chart{
  constructor(opts){
    this.data = opts.data;
    this.element = opts.element;

    this.draw();
  }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Fixed:

const chart = new Chart({element: document.querySelector('#graph')});

function init(data){
  chart.setData(data);
}

let getD1 = d3.csv('d1.csv', function(d){
                        function removeNaN(e,c){
                          if (e>0) {return e} else {return c}
                        }
                        return { date: d3.timeParse("%Y-%m-%d")(d.Date),
                                 aapl : d.AAPL, tsla : d.TSLA,
                                 aapl_sma: removeNaN(+d.SMA_AAPL,d.AAPL),
                                 tsla_sma: removeNaN(+d.SMA_TSLA,d.TSLA)
                        }
                      });

I'm using a scroller, so this is implemented with the scroller:

var gs = d3.graphScroll()
    .container(d3.select('#container'))
    .graph(d3.selectAll('.container #graph'))
    .eventId('uniqueId1')  // namespace for scroll and resize events
    .sections(d3.selectAll('.container #sections > div'))
    // .offset(innerWidth < 900 ? innerHeight - 30 : 200)
    .on('active', function(i){
      data2get[i].then(init); //calling .then on d3.csv() passes data to my class.
      chart.setColor(colors[i]);
    });
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!