It seems, due to asynch nature of the callback while calling d3.csv, the variables inside the callback are not accessible outside. Is there a workaround to this?
Here is my code -
var cprices;
d3.csv("../data/crudeprices.csv", function(data){
cprices = data;
getCrudePrices(data);
});
function getCrudePrices(data){
for(var i = 0; i < data.length; i++) {
//cprices.push(data[i].price);
//console.log(cprices[i]);
}
}
console.log("cprices " + cprices);
I want to read the csv file and load the data into an array outside the callback. But it seems this is not supported. Is there a solution/workaround to this? Ref. - csv to array in d3.js