Platform
Resources
Pricing
Sign in
Get started
SUGIMOTO Tatsuo
Designer, Artist, Researcher, Educator @sugi2000lab . co-translator for Japanese edition of “Generative Design” and “Code as Creative Medium”.
Workspace
Fork
Published
By
SUGIMOTO Tatsuo
Edited
Nov 8, 2019
Fork of
D3 Tutorial 15-5
Insert cell
md
`# D3 Tutorial 15-6`
Insert cell
dataset
=
[
[
5
,
20
]
,
[
480
,
90
]
,
[
250
,
50
]
,
[
100
,
33
]
,
[
330
,
95
]
,
[
410
,
12
]
,
[
475
,
44
]
,
[
25
,
67
]
,
[
85
,
21
]
,
[
220
,
88
]
,
[
600
,
150
]
]
;
Insert cell
w
=
500
Insert cell
h
=
300
Insert cell
padding
=
20
Insert cell
xScale
=
d3
.
scaleLinear
(
)
.
domain
(
[
0
,
d3
.
max
(
dataset
,
function
(
d
)
{
return
d
[
0
]
;
}
)
]
)
.
range
(
[
padding
,
w
-
padding
*
2
]
)
;
Insert cell
yScale
=
d3
.
scaleLinear
(
)
.
domain
(
[
0
,
d3
.
max
(
dataset
,
function
(
d
)
{
return
d
[
1
]
;
}
)
]
)
.
range
(
[
h
-
padding
,
padding
]
)
;
Insert cell
rScale
=
d3
.
scaleLinear
(
)
.
domain
(
[
0
,
d3
.
max
(
dataset
,
function
(
d
)
{
return
d
[
1
]
;
}
)
]
)
.
range
(
[
2
,
5
]
)
;
Insert cell
svg
=
{
const
svg
=
DOM
.
svg
(
w
,
h
)
d3
.
select
(
svg
)
.
selectAll
(
"circle"
)
.
data
(
dataset
)
.
enter
(
)
.
append
(
"circle"
)
.
attr
(
"cx"
,
function
(
d
)
{
return
xScale
(
d
[
0
]
)
;
}
)
.
attr
(
"cy"
,
function
(
d
)
{
return
yScale
(
d
[
1
]
)
;
}
)
.
attr
(
"r"
,
function
(
d
)
{
return
rScale
(
d
[
1
]
)
;
}
)
;
d3
.
select
(
svg
)
.
selectAll
(
"text"
)
.
data
(
dataset
)
.
enter
(
)
.
append
(
"text"
)
.
text
(
function
(
d
)
{
return
d
[
0
]
+
","
+
d
[
1
]
;
}
)
.
attr
(
"x"
,
function
(
d
)
{
return
xScale
(
d
[
0
]
)
;
}
)
.
attr
(
"y"
,
function
(
d
)
{
return
yScale
(
d
[
1
]
)
;
}
)
.
attr
(
"font-family"
,
"sans-serif"
)
.
attr
(
"font-size"
,
"11px"
)
.
attr
(
"fill"
,
"red"
)
;
return
svg
}
Insert cell
style
=
html
`<style>
</style>`
Insert cell
d3
=
require
(
'd3@5'
)
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
Compare fork
Fork
View
Export
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
dataset
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
w
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
h
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
padding
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
xScale
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
yScale
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
rScale
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
svg
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
style
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
d3
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML