There seems to be a bit of confusion here: you're mixing up d3.csv
, which is used for making requests, with d3.csvParse
, which is used for parsing strings (and also combining D3 v3 and D3 v4 syntax). Here's the distinction:
d3.csv (D3 v4)
The d3.csv function, takes arguments (url[[, row], callback])
:
Returns a new request for the CSV file at the specified url with the default mime type text/csv. (emphasis mine)
So, when you want to make a request for a specific CSV file at a given URL, you should use d3.csv
.
Take a look at this snippet that retrieves a CSV from a URL and logs the parsed data:
d3.csv("https://gist.githubusercontent.com/d3noob/fa0f16e271cb191ae85f/raw/bf896176236341f56a55b36c8fc40e32c73051ad/treedata.csv", function(data){
console.log(data);
});
d3.csvParse
In contrast, d3.csvParse (or d3.csv.parse
in D3 v3), takes arguments (string[, row])
:
Parses the specified string in delimiter-separated values format, returning an array of objects representing the rows.
Use d3.csvParse
when you need to parse a string, not when making a request like with d3.csv
.
For example, if you have a string like this:
var data = "foo,bar,baz\n42,33,42\n12,76,54\n13,42,17";
You would parse it using d3.csvParse
:
var data = "foo,bar,baz\n42,33,42\n12,76,54\n13,42,17";
var parsed = d3.csvParse(data);
console.log(parsed);