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

323
Vistas
D3 stacked chart---problems with stack()

I've been recently trying to recreate Mike Bostock's stacked chart, in the form he's presented in an Observable notebook here:

https://observablehq.com/@mbostock/most-popular-operating-systems-2003-2020

The code actually work in the notebook when I am plugging in the data, but seems to be crashing when I'm running it on the local environment. I'm no master of converting Observable notebook code to HTML/JS, but usually I can pull it off after some trial and error. This seems to be eluding me right now. When I'm running this code:

function _series(d3,data){return(
d3.stack()
    .keys(d3.group(data, d => d.Article).keys())
    .value(([, values], name) => values.get(name) || 0)
  (d3.rollup(data, ([d]) => d.stock, d => +d.date, d => d.Article))
)}

the function returns an array of arrays with only single inputs, while in the original notebook it actually returns an array of arrays with values for individual dates for individual items.

So my problem is that I don't actually understand what's happening in this code. Why is there a separate d3.rollup in brackets after the value is called? Is value actually called with two sets of arguments in two different brackets? My JavaScript is pretty bad, and it's not something I'm very acquainted with.

May the fact that it works in a notebook but not outside of it be somehow related to what's happening in Observable behind the scenes? How can I alter the code so that it can run outside of Observable?

Many thanks,

Raf

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I've been loading the data which looked pretty much exactly as it did in the notebook, but 'date' was a string and not a datetime. I didn't notice that in the notebook there was a separate cell dealing with date.

Anyways, after I parsed the dates everything works fine.

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