I have recently started working with d3.js and I'm facing some challenges. From what I understand, the second parameter passed in d3.json() is used to process data from a JSON file.
Here is my code:
d3.json(base_url() + "data/data.json", clean_data)
.then(function (dataset) {
global_dataset = dataset;
console.log(dataset.age);
})
.catch(() => console.log("could not load a file"));
function clean_data(d) {
console.log("i am here");
let balance = d.balance;
balance = balance.splice(1);
return { age: +d.age, balance: +balance };
}
When I run this code, the console.log(dataset) displays the original JSON data instead of the processed object returned by the clean_data() function.
This is how my JSON data is structured:
JSON URL
In the HTML file where this code resides, I have included the CDN link for d3.js :
<script src="https://d3js.org/d3.v5.min.js"></script>
My goal is to create a scatterplot using this JSON data with d3.js and promises.