Public
Edited
Apr 25, 2023
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
temperature_in_kathmandu_2022_area_chart =
areaChart(sampleCityData, {
x: "datetime",
y: "tempmax",

// Optional
width,
yLabel: "↑ Temp.",
yTickFormat: (d) => `${d3.format(".0f")(d)}°C`,
xLabel: "Date →"
})
Insert cell
Insert cell
temperature_in_kathmandu_and_pokhara_2022_area_chart =
areaChart(sampleData, {
x: "datetime",
y: "tempmax",
grouping: "name",

// Optional
width,
yLabel: "↑ Temp.",
yTickFormat: (d) => `${d3.format(".0f")(d)}°C`,
xLabel: "Date →"
})
Insert cell
Insert cell
areaChart(bls, {
x: "date",
y: "unemployed",
grouping: "industry",
stack: true,

// Optional
width,
yLabel: "↑ Unemployed",
yTickFormat: "s"
})
Insert cell
Insert cell
Insert cell
function areaChart(
data,
{
// Required
x = "x",
y = "y",
grouping,

// Optional
stack = false, // When true, stacks each group
width,
height,
yLabel,
yTickFormat,
xLabel,
xTickFormat,

fillOpacity,
strokeWidth = 0.75,
scheme = schemeCategory10
} = {}
) {
const yParams = stack ? { y } : { y2: y };

fillOpacity = fillOpacity == null && stack ? fillOpacity : 0.125;
const stroke = stack
? "white"
: grouping == null
? main.blue["700"]
: grouping;

scheme = stack ? scheme.slice().reverse() : scheme;

return Plot.plot({
width,
height,
y: { grid: true, label: yLabel, tickFormat: yTickFormat },
x: { label: xLabel, tickFormat: xTickFormat },
color: { legend: true, range: scheme },
marks: [
Plot.areaY(data, {
...yParams,
x,
fill: grouping == null ? main.blue["700"] : grouping,
fillOpacity,
stroke,
strokeWidth
}),

Plot.ruleY([0])
]
});
}
Insert cell
Insert cell
Insert cell
Insert cell
sampleData = rawWeatherData
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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.
Learn more