Platform
Resources
Pricing
Sign in
Get started
UTEC
Workspace
Fork
Public
By
Stuart Diego Arteaga Montes
Edited
Apr 11
Insert cell
Insert cell
<
svg
width
=
"190"
height
=
"160"
>
<
path
d
=
"M 10 80 C 40 10, 65 10, 95 80 S 150 150, 180 80"
stroke
=
"black"
fill
=
"transparent"
/>
</
svg
>
Insert cell
margin
=
(
{
top
:
30
,
right
:
30
,
bottom
:
20
,
left
:
40
}
)
Insert cell
width
Insert cell
height
=
500
Insert cell
dateExtent
=
d3
.
extent
(
injuriesByMonth
,
d
=>
d
.
date
)
Insert cell
x
=
d3
.
scaleTime
(
)
.
domain
(
dateExtent
)
.
range
(
[
margin
.
left
,
width
-
margin
.
right
]
)
Insert cell
maxInjuries
=
d3
.
max
(
injuriesByMonth
,
d
=>
d
.
injuries
)
Insert cell
y
=
d3
.
scaleLinear
(
)
.
domain
(
[
0
,
maxInjuries
]
)
.
nice
(
)
.
range
(
[
height
-
margin
.
bottom
,
margin
.
top
]
)
Insert cell
line
=
d3
.
line
(
)
.
x
(
d
=>
x
(
d
.
date
)
)
.
y
(
d
=>
y
(
d
.
injuries
)
)
Insert cell
line
(
injuriesByMonth
)
Insert cell
Insert cell
<
svg
width
=
${width}
height
=
${height}
>
<
path
d
=
${line(injuriesByMonth)}
fill
=
"none"
stroke
=
"steelblue"
/>
Insert cell
{
const
svg
=
d3
.
create
(
'svg'
)
.
attr
(
'width'
,
width
)
.
attr
(
'height'
,
height
)
;
svg
.
append
(
"path"
)
.
attr
(
'stroke'
,
'red'
)
.
attr
(
'stroke-widht'
,
3.5
)
.
attr
(
'fill'
,
'none'
)
.
attr
(
"d"
,
line
(
injuriesByMonth
)
)
return
svg
.
node
(
)
}
Insert cell
area
=
d3
.
area
(
)
.
x
(
d
=>
x
(
d
.
date
)
)
.
y1
(
d
=>
y
(
d
.
injuries
)
)
.
y0
(
d
=>
y
(
0
)
)
Insert cell
<
svg
width
=
${width}
height
=
${height}
>
<
path
d
=
${area(injuriesByMonth)}
fill
=
"steelblue"
/>
</
svg
>
Insert cell
{
const
svg
=
d3
.
create
(
'svg'
)
.
attr
(
'width'
,
width
)
.
attr
(
'height'
,
height
)
;
svg
.
append
(
"path"
)
.
attr
(
'stroke'
,
'red'
)
.
attr
(
'stroke-widht'
,
3.5
)
.
attr
(
'fill'
,
'pink'
)
.
attr
(
"d"
,
area
(
injuriesByMonth
)
)
return
svg
.
node
(
)
}
Insert cell
Insert cell
url
=
'https://gist.githubusercontent.com/DanielKerrigan/d01fc44e4cee0c5c2434f464497ba260/raw/982bcefac49be9fd29887cbaead524e033f6dad4/nyc-collisions-2019-reduced.csv'
Insert cell
dataset
=
(
await
d3
.
csv
(
url
,
crash
=>
(
{
date
:
d3
.
timeParse
(
'%m/%d/%Y'
)
(
crash
.
date
)
,
zip
:
crash
.
zip
,
borough
:
crash
.
borough
,
injured
:
+
crash
.
injured
,
}
)
)
)
.
filter
(
d
=>
d
.
borough
!==
''
&&
d
.
injured
>=
1
&&
d
.
zip
!==
''
)
Insert cell
injuriesByMonth
=
{
const
counts
=
d3
.
rollup
(
dataset
,
collisions
=>
d3
.
sum
(
collisions
,
c
=>
c
.
injured
)
,
d
=>
d3
.
timeMonth
(
d
.
date
)
.
getTime
(
)
)
;
return
Array
.
from
(
counts
,
(
(
[
date
,
count
]
)
=>
(
{
date
:
new
Date
(
date
)
,
injuries
:
count
}
)
)
)
;
}
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
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
margin
Add comment
Copy import
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
dateExtent
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
x
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
maxInjuries
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
line
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
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
area
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
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
url
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
dataset
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
injuriesByMonth
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML