Source
54 chart lines · 1 file · 1.3 kBBenchmark harness excluded · shared/mount.ts
U.S. industry unemployment1,708 records · CSV · 53.9 kB
@charts-poc/demo-data/industriesSelection: Complete published snapshot
- date
- Date
- industry
- string
- unemployed
- number
U.S. Bureau of Labor Statistics@observablehq/sample-datasets@1.0.1 · revision 732c0148de74 · industries.csv · ISC distribution; upstream source credited · SHA-256 4cfc13b6ebe0Pinned snapshot
cases/04-stacked-time-area/tanstack.ts54 lines · entry
cases/04-stacked-time-area/tanstack.ts
import { areaY, colorLegend, defineChart, ruleY } from '@tanstack/charts'
import { scaleLinear, scaleUtc } from 'd3-scale'
import { industries } from '@charts-poc/demo-data/industries'
import type { ConformanceInput, ConformanceMount } from '../../types'
import { tanstackMount } from '../../shared/mount'
const colors = [
'#4e79a7',
'#f28e2c',
'#e15759',
'#76b7b2',
'#59a14f',
'#edc949',
'#af7aa1',
'#ff9da7',
'#9c755f',
'#bab0ab',
]
const definition = (_input: ConformanceInput) =>
defineChart({
marks: [
areaY(industries, {
x: 'date',
y: 'unemployed',
color: 'industry',
fillOpacity: 0.78,
}),
ruleY([0]),
],
x: { scale: scaleUtc, axis: { label: 'Month' } },
y: {
scale: scaleLinear,
grid: true,
axis: { label: 'Unemployed (thousands)' },
},
color: {
range: colors,
legend: colorLegend({ label: 'Industry' }),
},
})
export const mount: ConformanceMount = tanstackMount(
definition,
'Unemployment by industry as stacked areas',
{
format: ({ datum }) =>
`${datum.industry} · ${datum.date.toLocaleDateString('en-US', {
month: 'short',
year: 'numeric',
timeZone: 'UTC',
})} · ${datum.unemployed.toLocaleString('en-US')} thousand unemployed`,
},
)