Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
D3.js Quick Start Guide

You're reading from   D3.js Quick Start Guide Create amazing, interactive visualizations in the browser with JavaScript

Arrow left icon
Product type Paperback
Published in Sep 2018
Publisher Packt
ISBN-13 9781789342383
Length 180 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Matthew Huntington Matthew Huntington
Author Profile Icon Matthew Huntington
Matthew Huntington
Arrow right icon
View More author details
Toc

Table of Contents (10) Chapters Close

Preface 1. Getting Started with D3.js FREE CHAPTER 2. Using SVG to Create Images Using Code 3. Building an Interactive Scatter Plot 4. Making a Basic Scatter Plot Interactive 5. Creating a Bar Graph Using a Data File 6. Animating SVG Elements to Create an Interactive Pie Chart 7. Using Physics to Create a Force-Directed Graph 8. Mapping 9. Other Books You May Enjoy

Create data/configuration variables

At the bottom of the <body> tag, we're referencing an app.js file. Let's create that file and add the following code to it:

var WIDTH = 360;
var HEIGHT = 360;
var radius = Math.min(WIDTH, HEIGHT) / 2;

var dataset = [
    { label: 'Bob', count: 10 },
    { label: 'Sally', count: 20 },
    { label: 'Matt', count: 30 },
    { label: 'Jane', count: 40 }
];
console.log(dataset);

To be sure that it's working and linked up properly, we've added console.log(dataset) to the bottom. Let's open index.html in Chrome and view the developer console, to make sure that everything is hooked up the way it should be:

Once we're sure that it's working, we can remove console.log(dataset);, as follows:

var WIDTH = 360;
var HEIGHT = 360;
var radius = Math.min(WIDTH, HEIGHT) / 2;
...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image