Public
Edited
Dec 2, 2022
Insert cell
Insert cell
Insert cell
task_1_solution = {
//define the svg
const width = 6;
const height = 3;
const svg = d3.create("svg").attr("viewBox", [0, 0, width, height]);
const X = d3.scaleBand()
.domain(data.map(d => d.city))
.range([0, width])

const Y = d3.scaleLinear()
.domain([0, data[0].percentage_green_area])
.range([0, height]);

//create the rectangles
svg.selectAll('rect')
.data(data)
.enter()
.append('rect')
.attr('x', d => X(d.city))
.attr('y', d => height - Y(d.percentage_green_area))
.attr('width', 0.5)
.attr('height', d => Y(d.percentage_green_area))
.attr('fill', '#A9D6B7');

return svg.node();
}
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
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