Loading data

One of the best features of D3 is that it has a bunch of great helper functions for loading data. While sometimes it's easier to have your code generate your dataset, most of the time, you'll be mapping real data to what you create with D3.

The reason we want to load data externally is that bootstrapping large datasets into the page with predefined variables isn't very practical. Loading hundreds of kilobytes of data takes a while, and doing so asynchronously lets the rest of the page render in the meantime. Plus, who wants all of that data smack-dab in the middle of your code anyway?

To make HTTP requests, D3 uses XMLHttpRequests (XHR for short). This limits us to loading data off the same domain as the script because of the browser's ...

Get D3.js: Cutting-edge Data Visualization now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.