I am trying to load an external json file to d3.js, but everytime I try to assign the loaded data to a variable (so later I can use it with data();) it gives me undefined at console.log. I feel like I tried everything but I cannot assign the data to a variable, not sure what is wrong here.
var dataset
function checkIt(data){
for (var i in data) {
var data_clean;
data_clean = data[i].Total
dataset = data_clean
}
}
console.log(dataset)
d3.json("data.json", checkIt);
The dataset
[
{
"Continent":"Europe",
"Country_Names":"Albania",
"Total":3.8
},
{
"Continent":"Europe",
"Country_Names":"Armenia",
"Total":5.4
},
{
"Continent":"Europe",
"Country_Names":"Austria",
"Total":64.7
},
{
"Continent":"Europe",
"Country_Names":"Azerbaijan",
"Total":29.3
}]