Platform
Resources
Pricing
Sign in
Contact us
Eric Field
Building and Using Tools to See. UVA Architecture + Data Science. IT Director. Instructor.
Workspace
Fork
Public
d3 layout and lib examples
By
Eric Field
Edited
Apr 10, 2024
3 forks
d3 layout and lib examples
dvlib_layout Overview
Line graphs
Area graphs
Sparkline
Donut or Pie
Pixel Matrix
Treemap
Pack Circles
Sunburst
Dendogram
Clusters
Word Cloud
Clusters - dynamic movement
Pack Circles - dynamic movement
Treemap - dynamic movement
Network Graph - nodes and edges
Combining Layouts - Donuts on GridMap
Radar
Rings - circle with hole mask
Beeswarm - Force Diagram
Heatmap
Pack Circles with Donuts inside
US map with Powerplant Pack Circles
Ring plot on Map - Trust Gap?
Force Directed clustering along a path
Fixed location Network Graph
Radial bar / line
Fitness rings
Curves / distance color gradient
SVG distance along path / curve
Filled Arc Polygon Bands
Connecting multiple visuals in one space
Sankey / Alluvial / Parallel Sets
Insert cell
Insert cell
<
svg
id
=
"base"
width
=
"500"
height
=
"550"
>
<
style
>
.
line
{
fill
:
none
;
stroke
:
#000000
}
</
style
>
<
g
id
=
"layer1"
transform
=
"translate(50 10)"
>
</
g
>
<
g
id
=
"layer2"
transform
=
"translate(50 300)"
>
</
g
>
</
svg
>
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
sortedData
=
world_gdp_growth_pivot
.
sort
(
(
a
,
b
)
=>
d3
.
ascending
(
toNum
(
a
[
"Year"
]
)
,
toNum
(
b
[
"Year"
]
)
)
)
;
// sort the data so it's ordered left to right by year. The data may already be, but let's make sure.
Insert cell
Insert cell
scaleX
=
d3
.
scaleLinear
(
)
.
domain
(
[
1960
,
2012
]
)
.
range
(
[
10
,
420
]
)
Insert cell
scaleY
=
d3
.
scaleLinear
(
)
.
domain
(
[
-
20
,
20
]
)
.
range
(
[
200
,
0
]
)
Insert cell
Insert cell
Insert cell
graph1Elem
=
d3
.
select
(
svgContainer
)
.
select
(
"#layer1"
)
// this goes in <g id="layer1"></g>
Insert cell
myline1
=
lineGraph
(
graph1Elem
,
sortedData
,
"Year"
,
"USA"
,
scaleX
,
scaleY
)
Insert cell
Insert cell
graph1Elem
.
append
(
"g"
)
.
attr
(
"transform"
,
"translate(10 200)"
)
.
call
(
xAxis
)
.
style
(
"color"
,
"#ccc"
)
;
Insert cell
graph1Elem
.
append
(
"g"
)
.
call
(
yAxis
)
.
style
(
"color"
,
"#ccc"
)
;
Insert cell
Insert cell
Insert cell
graph2Elem
=
d3
.
select
(
svgContainer
)
.
select
(
"#layer2"
)
// this goes in <g id="layer2"></g>
Insert cell
fieldsToGraph
=
[
"USA"
,
"CHN"
,
"BRA"
]
;
// a list array to draw multiple lines
Insert cell
colors
=
d3
.
schemeTableau10
;
// or use one of the built-in color sets. This one mimicks Tableau.
Insert cell
options
=
{
colorSet
:
colors
}
Insert cell
myLine2
=
multiLineGraph
(
graph2Elem
,
sortedData
,
"Year"
,
fieldsToGraph
,
scaleX
,
scaleY
,
options
)
;
Insert cell
Insert cell
graph2Elem
.
append
(
"g"
)
.
attr
(
"transform"
,
"translate(10 200)"
)
.
call
(
xAxis
)
.
style
(
"color"
,
"#ccc"
)
;
Insert cell
graph2Elem
.
append
(
"g"
)
.
call
(
yAxis
)
.
style
(
"color"
,
"#ccc"
)
;
Insert cell
Insert cell
Insert cell
xAxis
=
d3
.
axisBottom
(
)
.
scale
(
scaleX
)
.
tickFormat
(
d3
.
format
(
"d"
)
)
Insert cell
yAxis
=
d3
.
axisLeft
(
)
.
scale
(
scaleY
)
Insert cell
Purpose-built for displays of data
Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Try it for free
Learn more
Fork
View
Export
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
svgContainer
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
sortedData
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
scaleX
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
scaleY
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
graph1Elem
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
myline1
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
graph2Elem
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
fieldsToGraph
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
colors
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
options
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
myLine2
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
xAxis
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
yAxis
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML