Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
The joy of d3.js
Search
Makoto Inoue
January 30, 2013
3.8k
3
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
The joy of d3.js
Makoto Inoue
January 30, 2013
More Decks by Makoto Inoue
See All by Makoto Inoue
ENS beyond Web3
makoto_inoue
0
200
Tokyo ENS Meetup 2023 June
makoto_inoue
0
160
ENS for your community
makoto_inoue
0
380
ENS for the multi chain world @ EthPorto 2023
makoto_inoue
0
250
ENS on Starknet at StarkWare Session
makoto_inoue
0
200
Ethcc: The State of ENS 2022
makoto_inoue
0
380
EthShanghai ENS integration workshop - May 2022
makoto_inoue
0
220
ENS Integration workshop @ nfthack
makoto_inoue
0
140
ENS as your web3 username
makoto_inoue
0
460
Featured
See All Featured
The Pragmatic Product Professional
lauravandoore
37
7.5k
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
1
600
We Are The Robots
honzajavorek
0
440
AI: The stuff that nobody shows you
jnunemaker
PRO
10
1.3k
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
630
Java REST API Framework Comparison - PWX 2021
mraible
34
9.8k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.6k
Typedesign – Prime Four
hannesfritz
42
3.2k
Fantastic passwords and where to find them - at NoRuKo
philnash
53
4k
Discover your Explorer Soul
emna__ayadi
2
1.3k
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
1
600
Balancing Empowerment & Direction
lara
6
1.4k
Transcript
THE JOY OF D3.JS @makoto_inoue London d3.js Meetup Jan 2013
Wednesday, 30 January 13
THE JOY OF STATS http://blog.new-bamboo.co.uk/2013/01/07/the-joy-of-d3-js Wednesday, 30 January 13
THE GAP MINDER http://youtu.be/jbkSRLYSojo Wednesday, 30 January 13
BY @MBOSTOCK http://bost.ocks.org/mike/nations/ Wednesday, 30 January 13
BY @MAKOTO_INOUE http://makoto.github.com/the_joy_of_d3js/ Wednesday, 30 January 13
GOAL “Understand enough basic so that you can tweak examples
by yourself” Wednesday, 30 January 13
ON BENKYO PLAYER http://benkyoplayer.com/courses/3 Wednesday, 30 January 13
TOPICS 1.Introduction 2.Drawing Circles 3.Debugging 4.Basic Transition 5.Scaling 6.Array, Group
And Event 7.Loading Multiple Data files 8.Geo https://github.com/makoto/the_joy_of_d3js/wiki Wednesday, 30 January 13
DRAWING CIRCLES http://makoto.github.com/the_joy_of_d3js/circles.html Wednesday, 30 January 13
DRAWING CIRCLES var width = 500,height = 400, data =
[ {id:1,x:163,y:10}, {id:2,x:326,y:140}, {id:3,x:490,y:270} ] var svg = d3.select("body").append("svg") .attr({ class:"svg", width:width, height:height }) var circle = svg.selectAll("circle") .data(data); circle.enter().append("circle") .attr("cx", function(d){return d.x}) .attr("cy", function(d){return d.y}) .attr("r", 5) Wednesday, 30 January 13
DRAWING CIRCLES var width = 500,height = 400, data =
[ {id:1,x:163,y:10}, {id:2,x:326,y:140}, {id:3,x:490,y:270} ] var svg = d3.select("body").append("svg") .attr({ class:"svg", width:width, height:height }) var circle = svg.selectAll("circle") .data(data); circle.enter().append("circle") .attr("cx", function(d){return d.x}) .attr("cy", function(d){return d.y}) .attr("r", 5) Wednesday, 30 January 13
DRAWING CIRCLES var width = 500,height = 400, data =
[ {id:1,x:163,y:10}, {id:2,x:326,y:140}, {id:3,x:490,y:270} ] var svg = d3.select("body").append("svg") .attr({ class:"svg", width:width, height:height }) var circle = svg.selectAll("circle") .data(data); circle.enter().append("circle") .attr("cx", function(d){return d.x}) .attr("cy", function(d){return d.y}) .attr("r", 5) Wednesday, 30 January 13
DRAWING CIRCLES var width = 500,height = 400, data =
[ {id:1,x:163,y:10}, {id:2,x:326,y:140}, {id:3,x:490,y:270} ] var svg = d3.select("body").append("svg") .attr({ class:"svg", width:width, height:height }) var circle = svg.selectAll("circle") .data(data); circle.enter().append("circle") .attr("cx", function(d){return d.x}) .attr("cy", function(d){return d.y}) .attr("r", 5) Wednesday, 30 January 13
DRAWING CIRCLES var width = 500,height = 400, data =
[ {id:1,x:163,y:10}, {id:2,x:326,y:140}, {id:3,x:490,y:270} ] var svg = d3.select("body").append("svg") .attr({ class:"svg", width:width, height:height }) var circle = svg.selectAll("circle") .data(data); circle.enter().append("circle") .attr("cx", function(d){return d.x}) .attr("cy", function(d){return d.y}) .attr("r", 5) Wednesday, 30 January 13
DRAWING CIRCLES http://bost.ocks.org/mike/join/ Wednesday, 30 January 13
DRAWING CIRCLES var width = 500,height = 400, data =
[ {id:1,x:163,y:10}, {id:2,x:326,y:140}, {id:3,x:490,y:270} ] var svg = d3.select("body").append("svg") .attr({ class:"svg", width:width, height:height }) var circle = svg.selectAll("circle") .data(data); circle.enter().append("circle") .attr("cx", function(d){return d.x}) .attr("cy", function(d){return d.y}) .attr("r", 5) Wednesday, 30 January 13
BASIC TRANSITION http://makoto.github.com/the_joy_of_d3js/transitions.html Wednesday, 30 January 13
BASIC TRANSITION var width = 500, height = 400, data1
= [ {id:1,x:163,y:10}, {id:2,x:326,y:140}, ], data2 = [ {id:2,x:400,y:340}, {id:3,x:290,y:280} ]; var svg = d3.select("body").append("svg") .attr({ class:"svg", width:width, height:height }) Wednesday, 30 January 13
BASIC TRANSITION var chart = function(data){ var circle = svg.selectAll("circle")
.data(data, function(d){ return d.id }) circle.enter().append("circle") .attr("cx", function(d){return d.x}) .attr("cy", function(d){return d.y}) .attr("r", 0) circle.transition().duration(2000) .attr("cx", function(d){return d.x}) .attr("cy", function(d){return d.y}) .attr("r", 5) circle.exit() .remove() } chart(data1) Wednesday, 30 January 13
BASIC TRANSITION var chart = function(data){ var circle = svg.selectAll("circle")
.data(data, function(d){ return d.id }) circle.enter().append("circle") .attr("cx", function(d){return d.x}) .attr("cy", function(d){return d.y}) .attr("r", 0) circle.transition().duration(2000) .attr("cx", function(d){return d.x}) .attr("cy", function(d){return d.y}) .attr("r", 5) circle.exit() .remove() } chart(data1) Wednesday, 30 January 13
BASIC TRANSITION var chart = function(data){ var circle = svg.selectAll("circle")
.data(data, function(d){ return d.id }) circle.enter().append("circle") .attr("cx", function(d){return d.x}) .attr("cy", function(d){return d.y}) .attr("r", 0) circle.transition().duration(2000) .attr("cx", function(d){return d.x}) .attr("cy", function(d){return d.y}) .attr("r", 5) circle.exit() .remove() } chart(data1) Wednesday, 30 January 13
BASIC TRANSITION var chart = function(data){ var circle = svg.selectAll("circle")
.data(data, function(d){ return d.id }) circle.enter().append("circle") .attr("cx", function(d){return d.x}) .attr("cy", function(d){return d.y}) .attr("r", 0) circle.transition().duration(2000) .attr("cx", function(d){return d.x}) .attr("cy", function(d){return d.y}) .attr("r", 5) circle.exit() .remove() } chart(data1) Wednesday, 30 January 13
BASIC TRANSITION var chart = function(data){ var circle = svg.selectAll("circle")
.data(data, function(d){ return d.id }) circle.enter().append("circle") .attr("cx", function(d){return d.x}) .attr("cy", function(d){return d.y}) .attr("r", 0) circle.transition().duration(2000) .attr("cx", function(d){return d.x}) .attr("cy", function(d){return d.y}) .attr("r", 5) circle.exit() .remove() } chart(data1) Wednesday, 30 January 13
BASIC TRANSITION var chart = function(data){ var circle = svg.selectAll("circle")
.data(data, function(d){ return d.id }) circle.enter().append("circle") .attr("cx", function(d){return d.x}) .attr("cy", function(d){return d.y}) .attr("r", 0) circle.transition().duration(2000) .attr("cx", function(d){return d.x}) .attr("cy", function(d){return d.y}) .attr("r", 5) circle.exit() .remove() } chart(data1) Wednesday, 30 January 13
BASIC TRANSITION var chart = function(data){ var circle = svg.selectAll("circle")
.data(data, function(d){ return d.id }) circle.enter().append("circle") .attr("cx", function(d){return d.x}) .attr("cy", function(d){return d.y}) .attr("r", 0) circle.transition().duration(2000) .attr("cx", function(d){return d.x}) .attr("cy", function(d){return d.y}) .attr("r", 5) circle.exit() .remove() } chart(data1) Wednesday, 30 January 13
SCALING http://makoto.github.com/the_joy_of_d3js/scaling.html Wednesday, 30 January 13
SCALING year1 = [ { id:1, region:'africa', population: 10000,lifeExpectancy:163,income:10}, {
id:2, region:'asia', population: 20000,lifeExpectancy:326,income:140 }, ] year2 = [......] Wednesday, 30 January 13
SCALING var x = d3.scale.linear() .domain([0, 400]) .range([0, width -
100]); var y = d3.scale.linear() .domain([0,200]) .range([0, width - 100]) circle.enter().append("circle") .attr("cx", function(d){ return x(d.lifeExpectancy) }) .attr("cy", function(d){ return y(d.income) }) Wednesday, 30 January 13
SCALING var x = d3.scale.linear() .domain([0, 400]) .range([0, width -
100]); var y = d3.scale.linear() .domain([0,200]) .range([0, width - 100]) circle.enter().append("circle") .attr("cx", function(d){ return x(d.lifeExpectancy) }) .attr("cy", function(d){ return y(d.income) }) Wednesday, 30 January 13
SCALING http://www.jeromecukier.net/blog/2011/08/11/d3-scales-and-color/ Wednesday, 30 January 13
SCALING var x = d3.scale.linear() .domain([0, 400]) .range([0, width -
100]); var y = d3.scale.linear() .domain([0,200]) .range([0, width - 100]) circle.enter().append("circle") .attr("cx", function(d){ return x(d.lifeExpectancy) }) .attr("cy", function(d){ return y(d.income) }) Wednesday, 30 January 13
SCALING var yAxis = d3.svg.axis() .scale(y) .orient("left") .tickSize(1) svg.append("g") .attr("class",
"y axis"); d3.select(".y.axis") .call(yAxis); svg.append("text") .attr("class", "y label") .attr("text-anchor", "end") .attr("y", -45) .attr("x", -120) .attr("dy", ".75em") .attr("transform", "rotate(-90)") .text("life expectancy (years)"); Wednesday, 30 January 13
SCALING var yAxis = d3.svg.axis() .scale(y) .orient("left") .tickSize(1) svg.append("g") .attr("class",
"y axis"); d3.select(".y.axis") .call(yAxis); svg.append("text") .attr("class", "y label") .attr("text-anchor", "end") .attr("y", -45) .attr("x", -120) .attr("dy", ".75em") .attr("transform", "rotate(-90)") .text("life expectancy (years)"); Wednesday, 30 January 13
ARRAY, GROUP, EVENT http://makoto.github.com/the_joy_of_d3js/events.html Wednesday, 30 January 13
ARRAY, GROUP, EVENT var group = svg.selectAll(".group") .data(data, function(d){return d.country});
var groupEnter = group.enter().append('g') .attr('class', 'group') var groupUpdate = group.transition().duration(2000) var groupExit = d3.transition(group.exit()) .remove() groupEnter.append("circle") .attr("cx", function(d){return x(d.income)}) .attr("cy", function(d){return y(d.lifeExpectancy)}) .attr("r", 2) .style("fill", function(d){return color(d.country)}) .on('mouseover', function(d){ d3.select(this.parentElement).select('text') .style('opacity', 1) }) Wednesday, 30 January 13
ARRAY, GROUP, EVENT Wednesday, 30 January 13
ARRAY, GROUP, EVENT var group = svg.selectAll(".group") .data(data, function(d){return d.country});
var groupEnter = group.enter().append('g') .attr('class', 'group') var groupUpdate = group.transition().duration(2000) var groupExit = d3.transition(group.exit()) .remove() groupEnter.append("circle") .attr("cx", function(d){return x(d.income)}) .attr("cy", function(d){return y(d.lifeExpectancy)}) .attr("r", 2) .style("fill", function(d){return color(d.country)}) .on('mouseover', function(d){ d3.select(this.parentElement).select('text') .style('opacity', 1) }) Wednesday, 30 January 13
ARRAY, GROUP, EVENT var group = svg.selectAll(".group") .data(data, function(d){return d.country});
var groupEnter = group.enter().append('g') .attr('class', 'group') var groupUpdate = group.transition().duration(2000) var groupExit = d3.transition(group.exit()) .remove() groupEnter.append("circle") .attr("cx", function(d){return x(d.income)}) .attr("cy", function(d){return y(d.lifeExpectancy)}) .attr("r", 2) .style("fill", function(d){return color(d.country)}) .on('mouseover', function(d){ d3.select(this.parentElement).select('text') .style('opacity', 1) }) Wednesday, 30 January 13
GEO Wednesday, 30 January 13
GEO @olivernn will explain Wednesday, 30 January 13
THANKS @makoto_inoue Wednesday, 30 January 13