Platform
Solutions
Resources
Pricing
Sign in
Sign up
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
One platform
to build and deploy the best data apps
Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
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