Use D3 to calculate extreme values in a data set
Use D3 to scale data
Build scatterplots using D3 and SVG
Use D3 to add axes and gridlines to graphs
Add axis labels and titles to graphs
Build histograms using D3 and SVG
Build pie charts using D3 and SVG
Code: http://bit.ly/2tzBwFC
Live Site: http://bit.ly/2uTHcKT
d3.max(dataArr [, callback])
How to associate values to array elements
d3.min(dataArr [, callback])
d3.scaleLinear()
.domain([num1, num2])
.range([num3, num4])
example
1
17
-4
52
5
9
24
10
Code: http://bit.ly/2vTC8TY
Live Site: http://bit.ly/2w9NG4E
Life Expectancy
Births per Capita
d3.extent(dataArr [, callback])
calculates min an max, returns them in an array!
var people = [
{ name: "Brett", age: 40 },
{ name: "Mackenzie", age: 30 },
{ name: "Arya", age: 78 },
{ name: "Lee", age: 22 }
];
d3.extent(people, function(d) { return d.age; });
// [ 22, 78 ]
Code: http://bit.ly/2wa3JzE
Live Site: http://bit.ly/2tMPGzi
50
40
30
20
10
0
60
70
80
90
100
d3.axisBottom(scale)
d3.axisLeft(scale)
d3.axisRight(scale)
d3.axisTop(scale)
axis.tickSize([size])
Set a new tick size
Ticks stretch in the direction of the axis
(e.g. left for axisLeft)
axis.tickSizeOuter([size])
Set a new tick size just for the outer ticks
98, 53, 62, 70, 82, 38, 72, 52, 76, 58, 62, 19, 34, 54, 81, 34, 8, 91, 38, 61, 60, 5, 20, 16, 81
50
40
30
20
10
0
60
70
80
90
100
Code: http://bit.ly/2wvwnzg
d3.histogram()
histogram.value([value])
Specifies what value should be used when creating bins
histogram.domain([domain])
Specifies the domain of values (i.e. the min and max) for the histogram generator
Code: http://bit.ly/2vcN0M2
Live Site: http://bit.ly/2wwyzqq
histogram.thresholds([value])
num | # of bins | num | # of bins |
---|---|---|---|
1 | 1 | 11 | 12 |
2 | 2 | 12 | 12 |
3 | 2 | 13 | 12 |
4 | 5 | 14 | 12 |
5 | 5 | 15 | 12 |
6 | 5 | 16 | 12 |
7 | 5 | 17 | 12 |
8 | 5 | 18 | 12 |
9 | 12 | 19 | 25 |
10 | 12 | 20 | 25 |
scale.ticks([count])
<path d="M-222.94,-200.73,300,0,0,1,0,-300L0,0Z"
fill="rgb(26, 188, 156)">
</path>
<path d="M-259.80,150A300,300,0,0,1,-222.94,-200.73L0,0Z"
fill="rgb(236, 240, 241)"></path>
<path d="M0,-300A300,300,0,0,1,176.33,242.70L0,0Z"
fill="rgb(241, 196, 15)">
</path>
<path d="M176.33,242.70A300,300,0,0,1,-259.80,150L0,0Z"
fill="rgb(155, 89, 182)">
</path>
Code: http://bit.ly/2weZpQV
Live Site: http://bit.ly/2izEcxW
d3.scaleOrdinal()
Maps a discrete set of points (e.g. [1, 2, 3]) to another discrete set of points (e.g. ['a','b','c'])
SVG
Transformed g element
pie chart
pie chart
{
region: "Chile",
continent: "SA",
year: 1967,
births: 259729
}
"M1.7757378587636622e-14,-290
A290,290,0,1,1,-285.4954404332191,-50.91515974483682
L-147.67005539649264,-26.335427454225943
A150,150,0,1,0,9.184850993605149e-15,-150
Z"
d3.pie()
2π
360°
d3.arc()
Converts JavaScript objects into path commands
Examples
Code: http://bit.ly/2vzgFhz
Live Site: http://bit.ly/2vswiYQ
Examples
pie.sort([comparator])