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

112
Vistas
Javascript d3 no header for 1 of the CSVs

I've started using d3 to pass some CSV data, and normally my CSV's look like

num,value
1,2
3,1
5,2

but I'm loading one CSV with the filename "sample2.csv" which doesn't have any headers, and simply looks like

5,3
7,5

, the code I'm using looks like

d3.queue()
.defer(d3.csv, "sample1.csv").defer(d3.csv, "sample2.csv").defer(d3.csv, "sample3.csv")
.await(function(error, sample1, sample2, sample)
{
}

I've read that for the CSV without headers, you need to use csvParseRows

Is this correct? And how could I pass csvParseRows into my code for "sample2.csv"

Does anyone know much about d3 and how this could be done?

Thanks

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

0

If using d3.queue, you can parse the text of the csv as usual, then in the await function, you'll need to parse rows:

d3.queue()
  .defer(d3.text,"test.csv")
  .await(ready);
  
function ready(error, text) {
    var csv = d3.csvParseRows(text);    
    console.log(csv);
    /* use csv data */
}

The csvParseRows method takes a string of text representing the contents of the file, not the url of the file. We can get those contents with d3.text, process it once we've loaded it.


With d3v5 an higher though we'd not need d3-queue as we can use a very similar approach without:

d3.text("test.csv").then(ready)
  
function ready(text) {
    var csv = d3.csvParseRows(text);
    
    console.log(csv);
    /* use csv data */
}

And if we had many files:

Promise.all([d3.text("file1.csv"),d3.text("file2.csv")]).then(ready);
  
function ready(files) {
    var csvs = files.map(function(file) {
        return d3.csvParseRows(file);
    });
    
    console.log(csvs);
    
    /* use csv data */
}
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