SlideShare a Scribd company logo
Introduction to D3
Slides: http://golodhros.github.io/d3-intro
Marcos Iglesias
Online
Personal Blog
Eventbrite Engineering Blog
@golodhros
Next up
Introduction
Applications
Bar Chart Example
D3 Selection
Live coding
Introduction to D3
What is D3.js?
Data-Driven Documents
General Purpose Visualization Library
Manipulates data based documents
Open web standards (SVG, HTML, CSS and now
Canvas)
Allows interactions with your graphs
How does it work?
Loads data
Binds data to elements
Transforms those elements
Transitions between states
Example
D3 Niceties
Based on attaching data to the DOM
Styling of elements with CSS
Transitions and animations baked in
Total control over our graphs
Amazing community
Decent amount of publications
D3 v4 Update
More modular
Breaking changes
New standard
WHAT CAN YOU DO
WITH D3?
Bar charts
Pie charts
Bubble charts
Choropleth
Map projections
Dashboards
Algorithm visualization
Artistic visualizations
Interactive data
explorations
Code example
by Mike BostockBar chart example
Creating container
var margin = {top: 20, right: 20, bottom: 30, left: 40},
width = 960 - margin.left - margin.right,
height = 500 - margin.top - margin.bottom;
var svg = d3.select("body").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top +
Reference: Margin Convention
Setting up scales and axes
var x = d3.scale.ordinal()
.rangeRoundBands([0, width], .1);
var y = d3.scale.linear()
.range([height, 0]);
var xAxis = d3.svg.axis()
.scale(x)
.orient("bottom");
var yAxis = d3.svg.axis()
.scale(y)
.orient("left")
.ticks(10, "%");
Reference: Scales tutorial
Loading data
// Loads Data
d3.tsv("data.tsv", type, function(error, data) {
if (error) throw error;
// Chart Code here
});
// Cleans Data
function type(d) {
d.frequency = +d.frequency;
return d;
}
Drawing axes
// Rest of the scales
x.domain(data.map(function(d) { return d.letter; }));
y.domain([0, d3.max(data, function(d) { return d.frequency; })]);
// Draws X axis
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis);
// Draws Y axis
svg.append("g")
.attr("class", "y axis")
.call(yAxis)
.append("text")
.attr("transform", "rotate(-90)")
.attr("y", 6)
.attr("dy", ".71em")
Drawing bars
svg.selectAll(".bar")
.data(data)
.enter().append("rect")
.attr("class", "bar")
.attr("x", function(d) { return x(d.letter); })
.attr("width", x.rangeBand())
.attr("y", function(d) { return y(d.frequency); })
.attr("height", function(d) { return height - y(d.frequency); });
Reference: ,Thinking with joins General Update
Pattern
Output
Final code
var margin = {top: 20, right: 20, bottom: 30, left: 40},
width = 960 - margin.left - margin.right,
height = 500 - margin.top - margin.bottom;
var x = d3.scale.ordinal()
.rangeRoundBands([0, width], .1);
var y = d3.scale.linear()
.range([height, 0]);
var xAxis = d3.svg.axis()
.scale(x)
.orient("bottom");
var yAxis = d3.svg.axis()
.scale(y)
.orient("left")
.ticks(10, "%");
D3 SELECTIONS
Transform the DOM by
selecting elements and
joining to data
Selections
Subclass of array
Provides methods to create and manipulate
selected elements
Array of arrays of elements
Setup
// We have some random info
let data = 'randomStringToCreateAnArray'.split('');
Simplest Selection
// We create the root list element
let list = d3.select('.js-container')
.append('ul');
Data Join
let dataJoin = list.selectAll('.item')
// an empty selection, since the list container was empty
// looking for instantiations of data
.data(data);
// data, which would be bound to a
// selection
UPDATE, ENTER
AND EXIT PATTERN
Functions that set
properties
.text()
.property()
.style()
.attr()
Update
dataJoin.attr('class', 'update');
dataJoin
.attr('foo', function(d) {
return d.foo;
});
Enter
// for every time that we see data
// but we do not see an element
dataJoin.enter()
.append('li').classed('enter', true)
// we create an element
.merge(dataJoin)
// we merge the update and enter groups and apply an operation
.text(function(d) { return d; });
Exit
// Remove all elements as needed
dataJoin.exit().remove();
Resources
How Selections Work
Thinking with joins
General Update Pattern
Selection API Reference
LIVE CODING
List Example
https://codepen.io/Golodhros/pen/rLXAZw
Table Example
http://codepen.io/Golodhros/pen/jAgZAj
Learning resources
Introduction to D3
Block Explorer
Books
Introduction to D3
Introduction to D3
Introduction to D3
Introduction to D3
More
Mike Bostock
D3 Reference
d3 slack team
Conclusions
D3 is a visualization library
You can do amazing things with it
Data Joins are complex
but not too much...
Thanks for listening!
Twitter:
Check out
Slides:
@golodhros
my Blog
http://golodhros.github.io/d3-intro

More Related Content

PDF
Introduction to d3js (and SVG)
PDF
Utahjs D3
PDF
D3.js 30-minute intro
PPTX
D3.JS Tips & Tricks (export to svg, crossfilter, maps etc.)
PPTX
SVCC 2013 D3.js Presentation (10/05/2013)
PPTX
PPTX
Introduction to D3.js
Introduction to d3js (and SVG)
Utahjs D3
D3.js 30-minute intro
D3.JS Tips & Tricks (export to svg, crossfilter, maps etc.)
SVCC 2013 D3.js Presentation (10/05/2013)
Introduction to D3.js

What's hot (14)

PDF
D3 data visualization
PDF
Having fun with graphs, a short introduction to D3.js
PDF
Visual Exploration of Large Data sets with D3, crossfilter and dc.js
PDF
d3 is cool
PDF
Introduction to data visualisations with d3.js — Data Driven Documents
PDF
D3 Basic Tutorial
PDF
D3 js
PDF
Learn D3.js in 90 minutes
PPT
Supstat nyc subway
PPTX
Cph Scala meetup 14.10.2021
PDF
Introduction to data visualisation with D3
PDF
Charting with Google
PPTX
Batra computer centre
PDF
A Quick and Dirty D3.js Tutorial
D3 data visualization
Having fun with graphs, a short introduction to D3.js
Visual Exploration of Large Data sets with D3, crossfilter and dc.js
d3 is cool
Introduction to data visualisations with d3.js — Data Driven Documents
D3 Basic Tutorial
D3 js
Learn D3.js in 90 minutes
Supstat nyc subway
Cph Scala meetup 14.10.2021
Introduction to data visualisation with D3
Charting with Google
Batra computer centre
A Quick and Dirty D3.js Tutorial
Ad

Viewers also liked (7)

PDF
D3 workshop
PDF
Understanding D3
PDF
"Визуализация данных с помощью d3.js", Михаил Дунаев, MoscowJS 19
PDF
Big Data Introduction to D3
PDF
Intro to D3: Data-Driven Documents
PPTX
A Fast and Dirty Intro to NetworkX (and D3)
PDF
Визуализация данных в браузере с помощью D3.js / Михаил Дунаев (Rambler&Co)
D3 workshop
Understanding D3
"Визуализация данных с помощью d3.js", Михаил Дунаев, MoscowJS 19
Big Data Introduction to D3
Intro to D3: Data-Driven Documents
A Fast and Dirty Intro to NetworkX (and D3)
Визуализация данных в браузере с помощью D3.js / Михаил Дунаев (Rambler&Co)
Ad

Similar to Introduction to D3 (20)

PDF
The D3 Toolbox
PDF
Better d3 charts with tdd
PDF
Learning d3
PPTX
Academy PRO: D3, part 1
PDF
D3 js in Action Data visualization with JavaScript Second Edition Elijah Meeks
PDF
Advanced D3 Charting
PPT
Playing with d3.js
PPT
Data Visualizations with D3
PPTX
SVGD3Angular2React
PDF
elm-d3 @ NYC D3.js Meetup (30 June, 2014)
PDF
D3.js in Action: Data visualization with JavaScript 2nd Edition Elijah Meeks
PPTX
Svcc 2013-d3
PDF
D3.js: Data Visualization for the Web
PDF
Fun with D3.js: Data Visualization Eye Candy with Streaming JSON
PPTX
Dreamforce 2014 - Introduction to d3.js
PDF
D3: Easy and flexible data visualisation using web standards
PPTX
Scrollytelling
PPTX
D3 data visualization
PDF
Overview of D3.js (1)
PDF
d4 and friendly charting DSL for D3
The D3 Toolbox
Better d3 charts with tdd
Learning d3
Academy PRO: D3, part 1
D3 js in Action Data visualization with JavaScript Second Edition Elijah Meeks
Advanced D3 Charting
Playing with d3.js
Data Visualizations with D3
SVGD3Angular2React
elm-d3 @ NYC D3.js Meetup (30 June, 2014)
D3.js in Action: Data visualization with JavaScript 2nd Edition Elijah Meeks
Svcc 2013-d3
D3.js: Data Visualization for the Web
Fun with D3.js: Data Visualization Eye Candy with Streaming JSON
Dreamforce 2014 - Introduction to d3.js
D3: Easy and flexible data visualisation using web standards
Scrollytelling
D3 data visualization
Overview of D3.js (1)
d4 and friendly charting DSL for D3

Recently uploaded (20)

PPTX
Monitoring Stack: Grafana, Loki & Promtail
PDF
Cost to Outsource Software Development in 2025
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PPTX
Advanced SystemCare Ultimate Crack + Portable (2025)
PPTX
history of c programming in notes for students .pptx
PPTX
Why Generative AI is the Future of Content, Code & Creativity?
PDF
Complete Guide to Website Development in Malaysia for SMEs
PDF
CCleaner Pro 6.38.11537 Crack Final Latest Version 2025
PPTX
AMADEUS TRAVEL AGENT SOFTWARE | AMADEUS TICKETING SYSTEM
PDF
Salesforce Agentforce AI Implementation.pdf
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
Autodesk AutoCAD Crack Free Download 2025
PPTX
Oracle Fusion HCM Cloud Demo for Beginners
PDF
Designing Intelligence for the Shop Floor.pdf
PDF
Digital Systems & Binary Numbers (comprehensive )
PDF
iTop VPN 6.5.0 Crack + License Key 2025 (Premium Version)
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
Tally Prime Crack Download New Version 5.1 [2025] (License Key Free
PPTX
Log360_SIEM_Solutions Overview PPT_Feb 2020.pptx
Monitoring Stack: Grafana, Loki & Promtail
Cost to Outsource Software Development in 2025
Odoo Companies in India – Driving Business Transformation.pdf
Advanced SystemCare Ultimate Crack + Portable (2025)
history of c programming in notes for students .pptx
Why Generative AI is the Future of Content, Code & Creativity?
Complete Guide to Website Development in Malaysia for SMEs
CCleaner Pro 6.38.11537 Crack Final Latest Version 2025
AMADEUS TRAVEL AGENT SOFTWARE | AMADEUS TICKETING SYSTEM
Salesforce Agentforce AI Implementation.pdf
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Autodesk AutoCAD Crack Free Download 2025
Oracle Fusion HCM Cloud Demo for Beginners
Designing Intelligence for the Shop Floor.pdf
Digital Systems & Binary Numbers (comprehensive )
iTop VPN 6.5.0 Crack + License Key 2025 (Premium Version)
Design an Analysis of Algorithms II-SECS-1021-03
Tally Prime Crack Download New Version 5.1 [2025] (License Key Free
Log360_SIEM_Solutions Overview PPT_Feb 2020.pptx

Introduction to D3