Start by creating a new folder for your project. Within that folder, I recommend creating a sub-folder called
d3. Then download the latest version of d3.v7.js into that sub-folder. As of this writing, the current version of D3 is 7.3.0
D3 is also provided in a “minified” version, d3.v7.min.js, from which whitespace has been removed for smaller file sizes and faster load times. The functionality is the same, but typically you’d use the regular version while working on a project (for friendlier debugging), and then switch to the minified version once you’ve launched the project publicly (for optimized load times).
Alternatively, D3 is also available as a collection of modules. This means that it has been split into a collection of smaller pieces that work independently (for example scales or zooming). Using one or a few of these modules means you only load in what you need, which speeds up load time.
The choice is up to you, but in these tutorials we’ll be using the standard version.
Create a simple HTML page within your project folder named
index.html. Your folder structure should now look something like this:
Now paste the following into your HTML file, so it references D3 in the
You'll notice that the D3 file you included in your project folder has the filename extension
In some cases, you can just open your HTML file in a web browser to view it. However, when loading external data sources, it is more reliable to run a local web server and view your page from
http://localhost:8888/. You could use a server like MAMP, run a simple server using Python, or see the notes on the wiki on activating a quick, temporary server.
In these tutorials, since we will stick to hard-coded data rather than loading in external sources, you can get away with not setting up a web server. But you'll want to get used to doing this in your D3 learning journey, as it quickly becomes necessary.
Next up: Adding elements →