SlideShare a Scribd company logo
Academy PRO: D3, part 1
What is data visualisation?
Data visualization is the presentation of data in a graphical format.
Why you should visualize data?
● Visuals are processed faster by the brain
● Visuals are committed to long-term memory easier than text
● Visuals can reveal patterns, trends, changes, and correlations
● Visuals can help simplify complex information
● Visuals can often be more effective than words at changing people’s
minds
● Visuals help people see things that were not obvious to them before
History
The concept of using pictures to understand data has been around for
centuries, from maps and graphs in the 17th century to the invention of the
pie chart in the early 1800s.
Nowadays
● HTML
● SVG
● Canvas
Data-driven documents
D3 (or D3.js) is a JavaScript library for visualizing data using web standards. D3
helps you bring data to life using SVG, Canvas and HTML.
It was created by Mike Bostock. He now works at the New York Times who
sponsors his open source work.
D3 is good at
● being general purpose visualization library
● providing a way to map data to documents
● handling data transformation
● providing basic math and layout algorithms
Why D3?
You choose how to visualize
https://bl.ocks.org/kerryrodden/raw/7090426/
https://bl.ocks.org/curran/raw/a9555f8041f04a5cbfb53e6f5c53caae/
https://bl.ocks.org/mbostock/raw/4062045/
Instalation
● via NPM:
npm install d3-selection
● load directly from d3js.org:
<script src="https://d3js.org/d3-selection.v1.min.js"></script>
npm install d3
<script src="https://d3js.org/d3.v4.js"></script>
D3 vs jQuery
d3.json('foo.json',
function(err, data) { });
d3.select('#foo')
.style('background', '#000')
.attr('height', '500')
.on('click', function() {})
.append('div');
$.getJSON('foo.json',
function(data) { });
$('#foo')
.css('background', '#000')
.attr('width', '500')
.click(function() {})
.append($('<div></div>'));
What is SVG?
● SVG stands for Scalable Vector Graphics
● SVG is used to define vector-based graphics for the Web
● SVG defines the graphics in XML format
● SVG graphics do NOT lose any quality if they are zoomed or resized
● Every element and every attribute in SVG files can be animated
SVG Shapes
● Rectangle <rect>
● Circle <circle>
● Ellipse <ellipse>
● Line <line>
● Polyline <polyline>
● Polygon <polygon>
● Path <path>
● Text <text>
https://codepen.io/sahanr/pen/JrLEEY
Selections
Selections allow powerful data-driven transformation of the document object
model (DOM).
const block = d3.select('.container');
const rectangles = block.selectAll('rect');
https://codepen.io/sahanr/pen/aLYOQr
Selections
Difference
Only selectAll has special behavior regarding grouping; select preserves the
existing grouping. The select method differs because there is exactly one
element in the new selection for each element in the old selection. Thus,
select also propagates data from parent to child, whereas selectAll does not
(hence the need for a data-join)!
Modifying Elements
const svg = d3
.select('svg')
.attr('name', 'container') // add attribute
.classed('green', true); // add class
const paragraphs = svg
.selectAll('text')
.filter(':nth-child(even)')
.style('text-decoration', 'underline') // add styles
.text('new inner text'); // added text
https://codepen.io/sahanr/pen/yzKeqV
Creating element
The append and insert methods are wrappers on top of select, so they also
preserve grouping and propagate data.
const svg = d3
.select('svg')
.append('rect') // add new element
.attr('y', 30) // modify <rect> element
.attr('x', 0);
svg.select('text)
.remove(); // remove first text element
https://codepen.io/sahanr/pen/aLYmgG
Bound to data
The magic of D3 comes from the ability to use data and web page elements
together.
Elements can be selected and their appearance modified to reflect differences
in the data.
Data is not a property of the selection, but a property of its elements (__data__
property).
The data join
● pairs an object and an element;
● keeps track of new and old objects;
● lets you animate differences
between new & old.
d3.selectAll('text')
.data(data)
.enter()
.append('text');
Binding data
const block = d3.select('.container')
.selectAll('p') // an enmpty selection, looking for data
.data(['first', 'second', 'third']); // data, which would be bound to selection
block
.enter() // for every time that we see data, but we do not see an element
.append('p') // append an element
.text(function (d) {
return d;
}); // fill the element with text
https://codepen.io/sahanr/pen/NaMPdm
Binding data
Data is bound to elements one of several ways:
● Joined to groups of elements via selection.data
● Assigned to individual elements via selection.datum
● Inherited from a parent via append, insert, or select
Loading data
d3-request
This module provides a convenient alternative to XMLHttpRequest.
d3.text("/path/to/file.txt", function(error, text) {
if (error) throw error;
console.log(text); // Hello, world!
});
d3.json()
d3.tsv()
d3.csv()
d3.xml()
d3.html()
svg output
https://codepen.io/sahanr/pen/KXopZZ?editors=0010
Scale
Scales are a convenient abstraction for a fundamental task in visualization:
mapping a dimension of abstract data to a visual representation.
Scale
var scores = [96, 74, 88, 65, 82 ];
const xScale = d3.scaleLinear()
.domain([0, d3.max(scores)]) -----> value range of the dataset
.range([0, 300]); ----------------> value range for the visualized graph
newItemGroup
.append('rect')
.attr('class', 'bar')
.attr('width', (d) => xScale(d))
.attr('height', barHeight - 5);
https://codepen.io/sahanr/pen/YraXeP
Scale types
● linear - https://codepen.io/sahanr/pen/MEVbRP
● time - https://codepen.io/sahanr/pen/wrmobr
● sequential- https://codepen.io/sahanr/pen/oGyrNV
● quantize- https://codepen.io/sahanr/pen/gGeLNm
● ordinal - https://codepen.io/sahanr/pen/BwrQgd
Handling events
We can bind an event listener to any DOM element using d3.selection.on()
method.
https://codepen.io/sahanr/pen/mBxJxP
Links
https://bost.ocks.org/mike/join/ - Thinking with Joins,
https://bost.ocks.org/mike/circles/ - Three Little Circles,
https://bost.ocks.org/mike/selection/ - How Selections Work,
https://github.com/d3 - D3 docs
To be continued...

More Related Content

PPTX
Silverlight week5
PDF
Basics of google chrome developer tools
PPT
econstruct summary
PDF
3DRepo
DOCX
Online data deduplication for in memory big-data analytic systems
PDF
3D + MongoDB = 3D Repo
Silverlight week5
Basics of google chrome developer tools
econstruct summary
3DRepo
Online data deduplication for in memory big-data analytic systems
3D + MongoDB = 3D Repo

What's hot (10)

PPTX
UMLtoNoSQL : From UML domain models to NoSQL Databases
PDF
Advanced D3 Charting
PDF
Exploring Large Chemical Data Sets
PDF
NOSQL IMPLEMENTATION OF A CONCEPTUAL DATA MODEL: UML CLASS DIAGRAM TO A DOCUM...
PDF
D3 data visualization
PDF
Adding new type to Druid
PDF
A Quick and Dirty D3.js Tutorial
PPTX
Dom(document object model)
PPTX
The GetLOD Story
PPTX
Data base
UMLtoNoSQL : From UML domain models to NoSQL Databases
Advanced D3 Charting
Exploring Large Chemical Data Sets
NOSQL IMPLEMENTATION OF A CONCEPTUAL DATA MODEL: UML CLASS DIAGRAM TO A DOCUM...
D3 data visualization
Adding new type to Druid
A Quick and Dirty D3.js Tutorial
Dom(document object model)
The GetLOD Story
Data base
Ad

Similar to Academy PRO: D3, part 1 (20)

PPTX
Introduction to D3.js
PPTX
chapter 6 data visualization ppt.pptx
PDF
D3 Mapping Visualization
PPTX
D3.JS Tips & Tricks (export to svg, crossfilter, maps etc.)
PPTX
D3 & MeteorJS
PPTX
D3 & MeteorJS
PPTX
Arches Getty Brownbag Talk
PDF
The D3 Toolbox
PDF
"Визуализация данных с помощью d3.js", Михаил Дунаев, MoscowJS 19
PDF
Learn D3.js in 90 minutes
ODP
Html5
ODP
Html5
PDF
Autodesk civil3 d_tutorail
PPTX
Datascape Introduction
PPTX
Sharing Data Between Angular Components
PPTX
Module 2.3 Document Databases in NoSQL Systems
PDF
Charlotte Front End - D3
PDF
Sebastian Hellmann
PDF
A Modern Interface for Data Science on Postgres/Greenplum - Greenplum Summit ...
PDF
Data Visualizations with D3.js
Introduction to D3.js
chapter 6 data visualization ppt.pptx
D3 Mapping Visualization
D3.JS Tips & Tricks (export to svg, crossfilter, maps etc.)
D3 & MeteorJS
D3 & MeteorJS
Arches Getty Brownbag Talk
The D3 Toolbox
"Визуализация данных с помощью d3.js", Михаил Дунаев, MoscowJS 19
Learn D3.js in 90 minutes
Html5
Html5
Autodesk civil3 d_tutorail
Datascape Introduction
Sharing Data Between Angular Components
Module 2.3 Document Databases in NoSQL Systems
Charlotte Front End - D3
Sebastian Hellmann
A Modern Interface for Data Science on Postgres/Greenplum - Greenplum Summit ...
Data Visualizations with D3.js
Ad

More from Binary Studio (20)

PPTX
Academy PRO: D3, part 3
PPTX
Academy PRO: Cryptography 3
PPTX
Academy PRO: Cryptography 1
PPTX
Academy PRO: Advanced React Ecosystem. MobX
PPTX
Academy PRO: Docker. Part 4
PPTX
Academy PRO: Docker. Part 2
PPTX
Academy PRO: Docker. Part 1
PPTX
Binary Studio Academy 2017: JS team project - Orderly
PPTX
Binary Studio Academy 2017: .NET team project - Unicorn
PPTX
Academy PRO: React native - miscellaneous
PPTX
Academy PRO: React native - publish
PPTX
Academy PRO: React native - navigation
PPTX
Academy PRO: React native - building first scenes
PPTX
Academy PRO: React Native - introduction
PPTX
Academy PRO: Push notifications. Denis Beketsky
PPTX
Academy PRO: Docker. Lecture 4
PPTX
Academy PRO: Docker. Lecture 3
PPTX
Academy PRO: Docker. Lecture 2
PPTX
Academy PRO: Docker. Lecture 1
PPTX
Academy PRO: Node.js - miscellaneous. Lecture 5
Academy PRO: D3, part 3
Academy PRO: Cryptography 3
Academy PRO: Cryptography 1
Academy PRO: Advanced React Ecosystem. MobX
Academy PRO: Docker. Part 4
Academy PRO: Docker. Part 2
Academy PRO: Docker. Part 1
Binary Studio Academy 2017: JS team project - Orderly
Binary Studio Academy 2017: .NET team project - Unicorn
Academy PRO: React native - miscellaneous
Academy PRO: React native - publish
Academy PRO: React native - navigation
Academy PRO: React native - building first scenes
Academy PRO: React Native - introduction
Academy PRO: Push notifications. Denis Beketsky
Academy PRO: Docker. Lecture 4
Academy PRO: Docker. Lecture 3
Academy PRO: Docker. Lecture 2
Academy PRO: Docker. Lecture 1
Academy PRO: Node.js - miscellaneous. Lecture 5

Recently uploaded (20)

PDF
Hybrid model detection and classification of lung cancer
PPTX
The various Industrial Revolutions .pptx
PPTX
OMC Textile Division Presentation 2021.pptx
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
Getting started with AI Agents and Multi-Agent Systems
PDF
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
PDF
NewMind AI Weekly Chronicles – August ’25 Week III
PDF
2021 HotChips TSMC Packaging Technologies for Chiplets and 3D_0819 publish_pu...
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
project resource management chapter-09.pdf
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PPTX
Tartificialntelligence_presentation.pptx
PPTX
1. Introduction to Computer Programming.pptx
PPTX
O2C Customer Invoices to Receipt V15A.pptx
PPTX
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
PDF
Zenith AI: Advanced Artificial Intelligence
PDF
A novel scalable deep ensemble learning framework for big data classification...
PDF
A comparative study of natural language inference in Swahili using monolingua...
PPTX
TLE Review Electricity (Electricity).pptx
Hybrid model detection and classification of lung cancer
The various Industrial Revolutions .pptx
OMC Textile Division Presentation 2021.pptx
Programs and apps: productivity, graphics, security and other tools
Group 1 Presentation -Planning and Decision Making .pptx
Getting started with AI Agents and Multi-Agent Systems
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
NewMind AI Weekly Chronicles – August ’25 Week III
2021 HotChips TSMC Packaging Technologies for Chiplets and 3D_0819 publish_pu...
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
project resource management chapter-09.pdf
Assigned Numbers - 2025 - Bluetooth® Document
Tartificialntelligence_presentation.pptx
1. Introduction to Computer Programming.pptx
O2C Customer Invoices to Receipt V15A.pptx
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
Zenith AI: Advanced Artificial Intelligence
A novel scalable deep ensemble learning framework for big data classification...
A comparative study of natural language inference in Swahili using monolingua...
TLE Review Electricity (Electricity).pptx

Academy PRO: D3, part 1

  • 2. What is data visualisation? Data visualization is the presentation of data in a graphical format.
  • 3. Why you should visualize data? ● Visuals are processed faster by the brain ● Visuals are committed to long-term memory easier than text ● Visuals can reveal patterns, trends, changes, and correlations ● Visuals can help simplify complex information ● Visuals can often be more effective than words at changing people’s minds ● Visuals help people see things that were not obvious to them before
  • 4. History The concept of using pictures to understand data has been around for centuries, from maps and graphs in the 17th century to the invention of the pie chart in the early 1800s.
  • 6. Data-driven documents D3 (or D3.js) is a JavaScript library for visualizing data using web standards. D3 helps you bring data to life using SVG, Canvas and HTML. It was created by Mike Bostock. He now works at the New York Times who sponsors his open source work.
  • 7. D3 is good at ● being general purpose visualization library ● providing a way to map data to documents ● handling data transformation ● providing basic math and layout algorithms
  • 8. Why D3? You choose how to visualize https://bl.ocks.org/kerryrodden/raw/7090426/ https://bl.ocks.org/curran/raw/a9555f8041f04a5cbfb53e6f5c53caae/ https://bl.ocks.org/mbostock/raw/4062045/
  • 9. Instalation ● via NPM: npm install d3-selection ● load directly from d3js.org: <script src="https://d3js.org/d3-selection.v1.min.js"></script> npm install d3 <script src="https://d3js.org/d3.v4.js"></script>
  • 10. D3 vs jQuery d3.json('foo.json', function(err, data) { }); d3.select('#foo') .style('background', '#000') .attr('height', '500') .on('click', function() {}) .append('div'); $.getJSON('foo.json', function(data) { }); $('#foo') .css('background', '#000') .attr('width', '500') .click(function() {}) .append($('<div></div>'));
  • 11. What is SVG? ● SVG stands for Scalable Vector Graphics ● SVG is used to define vector-based graphics for the Web ● SVG defines the graphics in XML format ● SVG graphics do NOT lose any quality if they are zoomed or resized ● Every element and every attribute in SVG files can be animated
  • 12. SVG Shapes ● Rectangle <rect> ● Circle <circle> ● Ellipse <ellipse> ● Line <line> ● Polyline <polyline> ● Polygon <polygon> ● Path <path> ● Text <text> https://codepen.io/sahanr/pen/JrLEEY
  • 13. Selections Selections allow powerful data-driven transformation of the document object model (DOM). const block = d3.select('.container'); const rectangles = block.selectAll('rect'); https://codepen.io/sahanr/pen/aLYOQr Selections
  • 14. Difference Only selectAll has special behavior regarding grouping; select preserves the existing grouping. The select method differs because there is exactly one element in the new selection for each element in the old selection. Thus, select also propagates data from parent to child, whereas selectAll does not (hence the need for a data-join)!
  • 15. Modifying Elements const svg = d3 .select('svg') .attr('name', 'container') // add attribute .classed('green', true); // add class const paragraphs = svg .selectAll('text') .filter(':nth-child(even)') .style('text-decoration', 'underline') // add styles .text('new inner text'); // added text https://codepen.io/sahanr/pen/yzKeqV
  • 16. Creating element The append and insert methods are wrappers on top of select, so they also preserve grouping and propagate data. const svg = d3 .select('svg') .append('rect') // add new element .attr('y', 30) // modify <rect> element .attr('x', 0); svg.select('text) .remove(); // remove first text element https://codepen.io/sahanr/pen/aLYmgG
  • 17. Bound to data The magic of D3 comes from the ability to use data and web page elements together. Elements can be selected and their appearance modified to reflect differences in the data. Data is not a property of the selection, but a property of its elements (__data__ property).
  • 18. The data join ● pairs an object and an element; ● keeps track of new and old objects; ● lets you animate differences between new & old. d3.selectAll('text') .data(data) .enter() .append('text');
  • 19. Binding data const block = d3.select('.container') .selectAll('p') // an enmpty selection, looking for data .data(['first', 'second', 'third']); // data, which would be bound to selection block .enter() // for every time that we see data, but we do not see an element .append('p') // append an element .text(function (d) { return d; }); // fill the element with text https://codepen.io/sahanr/pen/NaMPdm
  • 20. Binding data Data is bound to elements one of several ways: ● Joined to groups of elements via selection.data ● Assigned to individual elements via selection.datum ● Inherited from a parent via append, insert, or select
  • 21. Loading data d3-request This module provides a convenient alternative to XMLHttpRequest. d3.text("/path/to/file.txt", function(error, text) { if (error) throw error; console.log(text); // Hello, world! }); d3.json() d3.tsv() d3.csv() d3.xml() d3.html()
  • 23. Scale Scales are a convenient abstraction for a fundamental task in visualization: mapping a dimension of abstract data to a visual representation.
  • 24. Scale var scores = [96, 74, 88, 65, 82 ]; const xScale = d3.scaleLinear() .domain([0, d3.max(scores)]) -----> value range of the dataset .range([0, 300]); ----------------> value range for the visualized graph newItemGroup .append('rect') .attr('class', 'bar') .attr('width', (d) => xScale(d)) .attr('height', barHeight - 5); https://codepen.io/sahanr/pen/YraXeP
  • 25. Scale types ● linear - https://codepen.io/sahanr/pen/MEVbRP ● time - https://codepen.io/sahanr/pen/wrmobr ● sequential- https://codepen.io/sahanr/pen/oGyrNV ● quantize- https://codepen.io/sahanr/pen/gGeLNm ● ordinal - https://codepen.io/sahanr/pen/BwrQgd
  • 26. Handling events We can bind an event listener to any DOM element using d3.selection.on() method. https://codepen.io/sahanr/pen/mBxJxP
  • 27. Links https://bost.ocks.org/mike/join/ - Thinking with Joins, https://bost.ocks.org/mike/circles/ - Three Little Circles, https://bost.ocks.org/mike/selection/ - How Selections Work, https://github.com/d3 - D3 docs

Editor's Notes

  • #10: dependency
  • #14: select, selectAll, null, parentNode, filter, function(d,i,n) empty, node, nodes, size
  • #16: property, html second parameter null
  • #18: what is data
  • #19: Instead of telling D3 how to do something, tell D3 what you want. why? how it works? perfomance
  • #20: key
  • #22: request, header, send, error, load
  • #23: add margins
  • #26: power, log, sqrt, identity Utc
  • #27: event, mouse, touch