Notebooks 2.0 is here.
Read the preview announcement
Platform
Resources
Pricing
Sign in
Get started
Ishan Ghosh
Workspace
Fork
Published
By
Ishan Ghosh
Edited
Jul 12, 2021
ISC
Fork of
Let’s Make a Bar Chart, Part 2
1
Insert cell
Insert cell
Insert cell
Insert cell
FileAttachment
(
"test.csv"
)
.
text
(
)
Insert cell
Insert cell
d3
.
csvParse
(
await
FileAttachment
(
"test.csv"
)
.
text
(
)
)
Insert cell
Insert cell
data
=
d3
.
csvParse
(
await
FileAttachment
(
"test.csv"
)
.
text
(
)
,
d3
.
autoType
)
Insert cell
Insert cell
"1"
+
"2"
// not 3
Insert cell
d3
.
max
(
[
"1"
,
"2"
,
"10"
]
)
// not "10"
Insert cell
Insert cell
x
=
d3
.
scaleLinear
(
)
.
domain
(
[
0
,
d3
.
max
(
data
,
d
=>
d
.
count
)
]
)
.
range
(
[
0
,
width
]
)
Insert cell
y
=
d3
.
scaleBand
(
)
.
domain
(
data
.
map
(
d
=>
d
.
shape
)
)
.
range
(
[
0
,
20
*
data
.
length
]
)
Insert cell
{
const
svg
=
d3
.
create
(
"svg"
)
.
attr
(
"width"
,
width
)
.
attr
(
"height"
,
y
.
range
(
)
[
1
]
)
.
attr
(
"font-family"
,
"sans-serif"
)
.
attr
(
"font-size"
,
"10"
)
.
attr
(
"text-anchor"
,
"end"
)
;
const
bar
=
svg
.
selectAll
(
"g"
)
.
data
(
data
)
.
join
(
"g"
)
.
attr
(
"transform"
,
d
=>
`translate(0,${
y
(
d
.
shape
)
})`
)
;
bar
.
append
(
"rect"
)
.
attr
(
"fill"
,
"steelblue"
)
.
attr
(
"width"
,
d
=>
x
(
d
.
count
)
)
.
attr
(
"height"
,
y
.
bandwidth
(
)
-
1
)
;
bar
.
append
(
"text"
)
.
attr
(
"fill"
,
"white"
)
.
attr
(
"x"
,
d
=>
x
(
d
.
value
)
-
3
)
.
attr
(
"y"
,
y
.
bandwidth
(
)
/
2
)
.
attr
(
"dy"
,
"0.35em"
)
.
text
(
d
=>
d
.
value
)
;
return
svg
.
node
(
)
;
}
Insert cell
Insert cell
Insert cell
width
=
420
Insert cell
d3
=
require
(
"d3@6"
)
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
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
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
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
data
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
Unpin
Add comment
Select
Duplicate
Copy link
Embed
Delete
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
x
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
y
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
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
width
Unpin
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
d3
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML