Platform
Resources
Pricing
Sign in
Get started
Berkeley MIDS W209 Information Visualization Course
Workspace
Fork
Public
By
Natacha Maheshe
Edited
Jan 19
Fork of
Setting up D3
Insert cell
md
`# Setting up D3`
Insert cell
{
const
svg
=
html
`<svg viewBox="0 0 ${
width
} ${
height
}"></svg>`
;
const
selSvg
=
d3
.
select
(
svg
)
;
// D3 code goes here
selSvg
.
append
(
"circle"
)
.
attr
(
"r"
,
50
)
// Changed radius to 50
.
attr
(
"cx"
,
width
/
2
)
// Center horizontally
.
attr
(
"cy"
,
height
/
2
)
// Center vertically
.
attr
(
"fill"
,
"steelblue"
)
;
return
svg
;
}
Insert cell
{
const
selSvg
=
d3
.
create
(
"svg"
)
.
attr
(
"viewBox"
,
[
0
,
0
,
width
,
height
]
)
;
selSvg
.
append
(
"circle"
)
.
attr
(
"r"
,
50
)
.
attr
(
"cx"
,
width
/
2
)
.
attr
(
"cy"
,
height
/
2
)
.
attr
(
"fill"
,
"steelblue"
)
;
return
selSvg
.
node
(
)
;
}
Insert cell
height
=
width
*
0.6
Insert cell
d3
=
require
(
"d3-selection@2"
)
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
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
height
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