Public
Edited
Jul 26, 2024
9 forks
5 stars
Insert cell
Insert cell
chart = {
const svg = d3.select(DOM.svg(w, h));
svg.selectAll("circle")
.data(data)
.join("circle")
.attr("cx", d => x(d.x))
.attr("cy", d => y(d.y))
.attr("r", d => r(d.y))
.attr("fill", d => c(d.y));

svg.selectAll("text")
.data(data)
.join("text")
.filter(d => d.y > 200)
.text(d => d.name.replace(/ .*/,'')) // Deleting everything after the first word
.attr("x", d => x(d.x))
.attr("y", d => y(d.y));

svg.append("g")
.call(xAxis);

svg.append("g")
.attr("transform", `translate(${w/2}, ${h-5})`)
.append('text')
.style("text-anchor", "middle")
.text("mpg")
.attr("class", 'x_text');

svg.append("g")
.call(yAxis);

svg.append("g")
.attr("transform", `translate(20, ${h/1.2})rotate(-90)`)
.append('text')
.style("text-anchor", "middle")
.text("Despesa Mitjana")
.attr("class", 'y_text');
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
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