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

107
Views
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 answers
Answer question

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