Platform
Resources
Pricing
Sign in
Get started
Justin Gosses
JavaScript | Python | Data Visualization | Web Development | Geology | Space | Analytics | IoT | Learn, Build Stuff, and Figure Things Out
Workspace
Fork
Public
By
Justin Gosses
Edited
Dec 6, 2022
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
d3
=
import
(
"d3"
)
Insert cell
<
div
id
=
"chart"
>
</
div
>
Insert cell
Insert cell
svg
=
d3
.
select
(
"#chart"
)
.
append
(
"svg"
)
.
attr
(
"width"
,
500
)
.
attr
(
"height"
,
500
)
Insert cell
xScale
=
d3
.
scaleBand
(
)
.
domain
(
data
.
map
(
d
=>
d
.
name
)
)
.
range
(
[
0
,
400
]
)
.
padding
(
0.2
)
Insert cell
data
=
[
{
name
:
"A"
,
value
:
10
}
,
{
name
:
"B"
,
value
:
20
}
,
{
name
:
"C"
,
value
:
30
}
,
{
name
:
"D"
,
value
:
40
}
,
{
name
:
"E"
,
value
:
50
}
]
Insert cell
yScale
=
d3
.
scaleLinear
(
)
.
domain
(
[
0
,
d3
.
max
(
data
,
d
=>
d
.
value
)
]
)
.
range
(
[
400
,
0
]
)
Insert cell
xAxis
=
d3
.
axisBottom
(
xScale
)
Insert cell
yAxis
=
d3
.
axisLeft
(
yScale
)
Insert cell
svg
.
append
(
"g"
)
.
attr
(
"transform"
,
"translate(50, 0)"
)
.
call
(
yAxis
)
;
Insert cell
svg
.
append
(
"g"
)
.
attr
(
"transform"
,
"translate(50, 400)"
)
.
call
(
xAxis
)
Insert cell
bars
=
svg
.
selectAll
(
"rect"
)
.
data
(
data
)
.
enter
(
)
.
append
(
"rect"
)
.
attr
(
"x"
,
d
=>
xScale
(
d
.
name
)
+
50
)
.
attr
(
"y"
,
d
=>
yScale
(
d
.
value
)
)
.
attr
(
"width"
,
xScale
.
bandwidth
(
)
)
.
attr
(
"height"
,
d
=>
400
-
yScale
(
d
.
value
)
)
.
attr
(
"fill"
,
"steelblue"
)
Insert cell
Insert cell
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
Edit
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
d3
Add comment
Copy import
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
svg
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
data
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
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
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
bars
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
allCommandsFromChartGPTExceptCreationOfHTMLDiv
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML