The then() method waits for an asynchronous Promise to finish before running a callback. In a D3 workflow, chaining then() to d3.csv() makes the complete, transformed dataset available for exploration and visualization. section 3.2.3 section 3.6
Use the callback to prepare data before creating the visualization:
- Wait until the external dataset has fully loaded. section 3.6
- Access the entire dataset as an array of objects. section 3.2.3
- Measure or reorganize the data with length, d3.max(), d3.min(), d3.extent(), and sort(). section 3.2.3
- Pass the prepared data to the visualization-building function. section 3.2.3
d3.csv("../data/data.csv", d => {
return {
technology: d.technology,
count: +d.count
};
}).then(data => {
console.log(data);
});
Chains then() to d3.csv(), converts each row, and logs the complete dataset after loading finishes. section 3.2.3
Measure data before building a bar chart
After loading and converting the CSV rows, use the then() callback to log data.length, find the minimum and maximum counts, sort technologies by count, and call createViz(data).




