Published
Edited
Sep 20, 2022
Fork of Untitled
Insert cell
chartData = {
const data = await FileAttachment("regional-sales.csv").csv({typed: true});
const xAccessor = data.columns[0];
const categories = data.columns.slice(1);

return Object.assign(
categories.flatMap(
category => data.map(
d => {
return { state: d[xAccessor], category, population: d[category] };
}
)
),
{ categories }
);
}
Insert cell
Plot.plot({
color: {
legend: true,
scheme: "spectral",
},
x: {
//paddingOuter: 0.2,
//paddingInner: 0.2,
padding: 0.70,
inset: 0,
align: 0.05,
type: "band",
domain: chartData.state
},
marks: [
Plot.barY(chartData, { x: 'state', y: 'population', fill: "category"}),
]
});
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