Platform
Resources
Pricing
Sign in
Contact us
Observable
The end-to-end solution for building and hosting better data apps, dashboards, and reports.
Workspace
Fork
Published
before / after
By
Zan
Edited
Feb 16, 2022
Fork of
Fork this: Ordered faceted area chart example 1
1 star
before / after
Instead of more colors, try an input to highlight your bar chart
Fork this: text input to highlight a bar chart
Instead of a stacked area chart, try an ordered 'faceted' chart.
Fork this: Ordered faceted area chart example 1
Fork this: Ordered faceted area chart #2
Insert cell
Insert cell
Insert cell
// replace with your data by uploading or importing a different CSV
import
{
unemployment
as
data
}
from
"@d3/stacked-area-chart"
Insert cell
categoriesName
=
"industry"
Insert cell
metricName
=
"unemployed"
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// a few functions to choose from for sorting the categories
sortOptions
=
(
{
'alphabetical'
:
(
a
,
b
)
=>
a
[
0
]
>
b
[
0
]
?
1
:
-
1
,
'largest to smallest'
:
(
a
,
b
)
=>
b
[
1
]
-
a
[
1
]
,
'smallest to largest'
:
(
a
,
b
)
=>
a
[
1
]
-
b
[
1
]
,
}
)
Insert cell
// extracts and sums the categories from the data based on the metricName and categoriesName
categoriesRolledUp
=
d3
.
rollups
(
data
,
v
=>
d3
.
sum
(
v
,
d
=>
d
[
metricName
]
)
,
d
=>
d
[
categoriesName
]
)
Insert cell
// extracts the names of the categories from the categoriesRollupUp array
categories
=
categoriesRolledUp
.
map
(
d
=>
d
[
0
]
)
Insert cell
// filter and sort the categorical strings based on the selections from the checkboxes and radio buttons
categoriesFilteredSorted
=
categoriesRolledUp
.
filter
(
d
=>
categoriesToShow
.
includes
(
d
[
0
]
)
)
.
sort
(
sortOptions
[
selectedSortOption
]
)
.
map
(
d
=>
d
[
0
]
)
Insert cell
dataFiltered
=
data
.
filter
(
d
=>
categoriesFilteredSorted
.
includes
(
d
[
categoriesName
]
)
)
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
intro
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
categoriesName
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
metricName
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
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
categoriesToShow
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
selectedSortOption
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
normalizeY
Edit
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
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
sortOptions
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
categoriesRolledUp
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
categories
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
categoriesFilteredSorted
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
dataFiltered
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML