Public
Edited
Feb 5, 2021
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
{
const data = await d3.csv(
'https://raw.githubusercontent.com/italia/covid19-opendata-vaccini/master/dati/consegne-vaccini-latest.csv',
d3.autoType
);

let fig = figure({ title: 'Figure title' });
let ax = fig.subplot({ title: 'Axes title' });

ax.bar(data, {
x: { field: 'area' },
y: { field: 'numero_dosi' },
hue: { field: 'fornitore', domain: ['Pfizer/BioNTech', 'Moderna'] }
});

return fig.create().node();
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
{
const scale = d3
.scaleOrdinal()
.domain(["a", "b", "c", "d", "e"])
.range([
"rgb(153, 107, 195)",
"rgb(56, 106, 197)",
"rgb(93, 199, 76)",
"rgb(223, 199, 31)",
"rgb(234, 118, 47)"
]);

let legend = d3
.legendColor()
.shape(
"path",
d3
.symbol()
.type(d3.symbolTriangle)
.size(150)()
)
// Try commenting shapePadding() to see the difference
.shapePadding(25) // cell padding
.labelOffset(20) // label offset from the shape
.scale(scale);

const svg = d3.select(DOM.svg(80, 140));
svg
.append("g")
.attr("class", "legend legend--ordinal")
.attr("transform", "translate(20,20)");

svg.select(".legend").call(legend);

return svg.node();
}
Insert cell
Insert cell
toID = str => `${str}`.replace(/\W/g, '_')
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