Platform
Resources
Pricing
Sign in
Get started
Brett Romero
Data scientist, amateur web developer and visualization enthusiast.
Workspace
Fork
Published
By
Brett Romero
Edited
Feb 23, 2021
MIT
9 stars
Insert cell
Insert cell
Insert cell
Insert cell
data
=
[
{
"name"
:
"foo"
,
"x"
:
10
,
"y"
:
20
}
,
{
"name"
:
"bar"
,
"x"
:
30
,
"y"
:
60
}
,
{
"name"
:
"stuff"
,
"x"
:
15
,
"y"
:
175
}
,
{
"name"
:
"something really long"
,
"x"
:
40
,
"y"
:
212
}
,
{
"name"
:
"something even longer akhdihfi"
,
"x"
:
2
,
"y"
:
300
}
]
Insert cell
Insert cell
measure
=
{
svg
.
append
(
"g"
)
.
style
(
"font"
,
"14px sans-serif"
)
.
style
(
"fill"
,
"#000"
)
.
selectAll
(
"text"
)
.
data
(
data
)
.
join
(
"text"
)
.
attr
(
"x"
,
d
=>
d
.
x
)
.
attr
(
"y"
,
d
=>
d
.
y
)
.
text
(
d
=>
d
.
name
)
;
return
svg
.
node
(
)
}
Insert cell
function
update
(
data
)
{
svg
.
selectAll
(
"text"
)
.
join
(
data
)
.
each
(
function
(
d
)
{
d
.
bbox
=
this
.
getBBox
(
)
;
}
)
;
}
Insert cell
chart
=
{
const
svg
=
d3
.
create
(
"svg"
)
.
attr
(
"viewBox"
,
[
0
,
0
,
400
,
400
]
)
;
update
(
data
)
;
const
xMargin
=
4
const
yMargin
=
2
svg
.
append
(
"g"
)
.
selectAll
(
"rect"
)
.
data
(
data
)
.
join
(
"rect"
)
.
attr
(
"x"
,
d
=>
d
.
x
)
.
attr
(
"y"
,
d
=>
d
.
y
)
.
style
(
"fill"
,
"black"
)
.
style
(
"opacity"
,
"0.5"
)
.
attr
(
"width"
,
d
=>
d
.
bbox
.
width
+
2
*
xMargin
)
.
attr
(
"height"
,
d
=>
d
.
bbox
.
height
+
2
*
yMargin
)
.
attr
(
'transform'
,
function
(
d
)
{
return
`translate(-${
xMargin
}, -${
d
.
bbox
.
height
*
0.8
+
yMargin
})`
}
)
;
svg
.
append
(
"g"
)
.
style
(
"font"
,
"14px sans-serif"
)
.
style
(
"fill"
,
"#FFF"
)
.
selectAll
(
"text"
)
.
data
(
data
)
.
join
(
"text"
)
.
attr
(
"x"
,
d
=>
d
.
x
)
.
attr
(
"y"
,
d
=>
d
.
y
)
.
text
(
d
=>
d
.
name
)
;
return
svg
.
node
(
)
}
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
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
d3
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
data
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
svg
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
measure
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
update
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
chart
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML