I need to read csv file with d3.js. My data file is
x,y
480,200
580,400
680,100
780,300
180,300
280,100
380,400
and my code is
var ball_1 = []
d3.csv("data.csv", function(data) {
ball_1 = data.map(function(d) { return [ +d["x"], +d["y"] ]; });
});
console.log(ball_1)
and the console log says
Array [ ]
but if I just write the data array explicitly in code,
var ball_1 = [
[480, 200],
[580, 400],
[680, 100],
[780, 300],
[180, 300],
[280, 100],
[380, 400]
];
console.log(ball_1)
Then console log says
Array [ Array[2], Array[2], Array[2], Array[2], Array[2], Array[2], Array[2] ]
So the first code for reading csv file does not work. What's wrong?