2

I want to assign the data that is loaded from a csv file using d3.csv(), to a global variable, so I can use it later on in my code, but I am get undefined for the global variable dataset.

var dataset;

d3.csv("/csv/census_tracts.csv", function(data){
   dataset=data;
   });

console.log(dataset);

1 Answers1

2

is problem of Asynchronous, try with setTime

for instance:

var dataset;

d3.csv("/csv/census_tracts.csv", function(data){
   dataset=data;
   });
setTimeout(function(){
console.log(dataset);
},200);