Public
Edited
Dec 16, 2022
1 fork
Insert cell
Insert cell
Insert cell
data = FileAttachment("world.geojson").json()
Insert cell
Insert cell
chart0 = {
const width=400, height=600;
const svg = d3.select(DOM.svg(width, height))
// Use Mercator projection
var projection = d3.geoMercator()
.fitExtent([[20, 20], [width, height]], data)

var path = d3.geoPath()
.projection(projection);
// Draw each province as a path
svg.append('g').selectAll('path')
.data(data.features)
.enter().append('path')
.attr('d', path)
// Styling
.style('stroke', '#ccc')
.style("fill", "gray");
return svg.node()
}
Insert cell
Insert cell
chart1 = {
const width=400, height=600;
const svg = d3.select(DOM.svg(width, height))
// Use Mercator projection
var projection = d3.geoMercator()
.fitExtent([[20, 20], [width, height]], data)

var path = d3.geoPath()
.projection(projection);
// Draw each province as a path
svg.append('g').selectAll('path')
.data(data.features)
.enter().append('path')
.attr('d', path)
// Styling
.style('stroke', '#ccc')
.style("fill", d => {
if (d.properties.name === "Uruguay"){
return "red"
}
if (d.properties.name === "Italy"){
return "red"
}
if (d.properties.name === "Germany"){
return "red"
}
if (d.properties.name === "Brazil"){
return "red"
}
if (d.properties.name === "England"){
return "red"
}
if (d.properties.name === "Argentina"){
return "red"
}
if (d.properties.name === "France"){
return "red"
}
if (d.properties.name === "Spain"){
return "red"
}
else {
return "gray"
}
});
return svg.node()
}
Insert cell
Insert cell
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