A Promise is an object representing the result of an asynchronous operation. In D3, d3.csv() returns a Promise while the browser loads an external dataset. section 3.2.3
Use then() to wait until loading finishes. Its callback receives the complete dataset, allowing you to inspect, measure, reorganize, and visualize the data. section 3.2.3 section 3.6
A Promise-based D3 data workflow can:
- Transform each CSV row while loading, including converting count strings into numbers. section 3.2.3
- Measure the complete array after loading with length, d3.max(), d3.min(), or d3.extent(). section 3.2.3
- Sort the data and pass it to a visualization function only after it is available. section 3.2.3
Load and use a CSV dataset
d3.csv("../data/data.csv", d => ({ technology: d.technology, count: +d.count })).then(data => { console.log(data.length); data.sort((a, b) => b.count - a.count); createViz(data); });
d3.csv("../data/weekly_temperature.csv", d3.autoType).then(data => {
console.log("temperature data", data);
});
Follow the complete Promise chain from loading and automatic type conversion to logging the finished dataset. section 4.1






