Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

191
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda