I am trying to read a csv file into d3.js. The previous question that I am directed to does not answer correctly. When I try that code it also does not return anything in the console My code is
d3.xml("continents.svg", "image/svg+xml", function(xml) {
var importedNode = document.importNode(xml.documentElement, true);
d3.select("#viz").node().appendChild(importedNode);
var data = d3.csv("new_data.csv", function(d) {
return {
country: d.Country_Names,
value: +d.Total // convert "Length" column to number
};
}, function(error, rows) {
console.log(rows);
});
console.log(data)
});
By this I wish to see the data in console however nothing appears there.
Data
Continent Country_Names Total
Europe Albania 3.8
Europe Armenia 5.4
Europe Austria 64.7
Europe Azerbaijan 29.3
Europe Belarus 6.8
Europe Belgium 104.6
Europe Bosnia and Herzegovina 21.2
Europe Bulgaria 44.3
Europe Croatia 17.2
Update the follwoing code also doesn’t work
var data;
function doSomethingWithData(data) {
console.log(data);
}
d3.csv("new_data.csv", doSomethingWithData);
});
neither does this one
var localData;
function doSomething() {
console.log(localData);
}
d3.csv("new_data.csv", function(csvData) {
localData = csvData;
doSomething();
});