Platform
Solutions
Resources
Pricing
Sign in
Sign up
Tomas Carnecky
Workspace
Fork
Published
By
Tomas Carnecky
Edited
Feb 26, 2021
Insert cell
Insert cell
Table
(
d3
.
csvParse
(
data
)
,
{
columns
:
[
"country"
,
"year"
,
"co2"
,
"methane"
]
,
format
:
{
co2
:
sparkbar
(
d3
.
max
(
d3
.
csvParse
(
data
)
,
d
=>
parseInt
(
d
.
co2
,
10
)
??
0
)
)
,
methane
:
sparkbar
(
d3
.
max
(
d3
.
csvParse
(
data
)
,
d
=>
parseInt
(
d
.
methane
,
10
)
??
0
)
)
,
}
}
)
Insert cell
function
sparkbar
(
max
)
{
return
x
=>
html
`<div style="
background: steelblue;
width: ${
100
*
x
/
max
}%;
float: right;
padding-right: 3px;
box-sizing: border-box;
color: white;">${
x
.
toLocaleString
(
"en"
)
}`
}
Insert cell
d3
=
require
(
"d3"
)
Insert cell
import
{
Table
}
from
"@observablehq/inputs"
Insert cell
data
=
await
fetch
(
"https://raw.githubusercontent.com/owid/co2-data/master/owid-co2-data.csv"
)
.
then
(
res
=>
res
.
text
(
)
)
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
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
sparkbar
Add comment
Copy import
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
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