Public
Edited
Jan 14, 2024
Importers
Insert cell
Insert cell
viewof amount = Inputs.range([0, 200], {label: "Amount", step: 1})
Insert cell
world.csv
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
viewof tipPercent = Inputs.radio([10, 12, 15, 18, 20, 25],
{label: "Tip Percentage", value: 20})
Insert cell
tip = amount * (tipPercent / 100)
Insert cell
A **${tipPercent}%** tip on **$${amount.toFixed(2)}** is **$${tip.toFixed(2)}**, for a total of **$${(amount+tip).toFixed(2)}**
Insert cell
groupData-2022@1.csv
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
global = (d3.sum(groupdata20221, d=>d.Population*d.PerCapPower)/1000).toFixed(2)
Insert cell
groupdata20221
X
Region
Y
PerCapPower
Color
Size
Facet X
Facet Y
Mark
bar
Type Chart, then Shift-Enter. Ctrl-space for more options.

Insert cell
Insert cell
mychart2 = Plot.plot({
y: {label: "Per Capita Power (watts)"},
x: {label: "Population (million)"},
marks: [
Plot.rectY(groupdata20221, Plot.stackX(
{x: "Population", y2: "PerCapPower", fill: "Region",
title: (d) => `${d.Region} ${d.str}`
})),
Plot.text(groupdata20221,{
Plot.stackX({x: "Population"}),
y: "PerCapPower",
textAnchor: "middle",
dy: -5,
text:(d) => `${d.PerCapPower.toFixed(2)}`
}),
Plot.text([[4000,800]], {textAnchor: "start",
text: d=>[`Total current global power 2022: ${global} GW\n
IEA NetZero by 2050 target: ${global *2.6} GW`]})
]
})
Insert cell
mychart2 = Plot.plot({
y: {label: "Per Capita Power (watts)"},
x: {label: "Population (million)"},
marks: [
Plot.rectY(groupdata20221, Plot.stackX(
{x: "Population", y2: "PerCapPower", fill: "Region",
title: (d) => `${d.Region} ${d.str}`
})),
Plot.text(groupdata20221,{
Plot.stackX({x: "Population"}),
y: "PerCapPower",
textAnchor: "middle",
dy: -5,
text:(d) => `${d.PerCapPower.toFixed(2)}`
}),
Plot.text([[4000,800]], {textAnchor: "start",
text: d=>[`Total current global power 2022: ${global} GW\n
IEA NetZero by 2050 target: ${global *2.6} GW`]})
]
})
Insert cell
groupCountries-2022.csv
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
groupData-2022.csv
X
Region
Y
PerCapPower
Color
xmin
Size
Facet X
Facet Y
Mark
bar
Type Chart, then Shift-Enter. Ctrl-space for more options.

Insert cell
Plot.plot({
color: { legend: true },
marks: [
Plot.barY(
groupdata20221,
{ x: "Region", y: "PerCapPower", fill: "xmin", tip: true ,title: "str"}
),
Plot.ruleY([0]),
Plot.text(groupdata20221,{x: "Region", y: "PerCapPower",text: (d)=>`${d.PerCapPower.toFixed(2)}`})
]
})
Insert cell
Plot.plot({
marks: [
Plot.rectY(groupdata20221, {x: "Population", y: "PerCapPower", sort: {x: "y", reverse: false}}),
Plot.ruleY([0])
]
})
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.
Learn more