read csv/tsv with no header line in D3

Use d3.text to load the data, and then d3.csvParseRows to parse it. For example:

d3.text("data/testnh.csv", function(text) {
  console.log(d3.csvParseRows(text));
});

You’ll probably also want to convert your columns to numbers, because they’ll be strings by default. Assume they are all numbers, you could say:

d3.text("data/testnh.csv", function(text) {
  var data = d3.csvParseRows(text).map(function(row) {
    return row.map(function(value) {
      return +value;
    });
  });
  console.log(data);
});

Leave a Comment