Public
Edited
May 30, 2024
11 forks
2 stars
Insert cell
Insert cell
chart = {
const svg = d3
.create("svg")
.attr("viewBox", [0, 0, width, height])
.style("overflow", "visible");

svg
.selectAll("circle")
.data(data)
.join("circle")
.attr("cx", (d) => x(d[0]))
.attr("cy", (d) => y(d[1]))
.attr("r", (d) => r(d[1]))
.attr("fill", (d) => c(d[1]));

svg
.selectAll("text")
.data(data)
.join("text")
.filter((d) => d[1] > 90)
.text((d) => d[0] + " | " + d[1])
.attr("x", (d) => x(d[0]))
.attr("y", (d) => y(d[1]))
.style("text-anchor", "middle");

return svg.node();
}
Insert cell
Insert cell
x = d3
.scaleLinear()
.domain(d3.extent(data, (d) => d[0]))
.range([margin.left, width - margin.right])
Insert cell
Insert cell
y = d3
.scaleLinear()
.domain([0, d3.max(data, (d) => d[1])])
.range([height - margin.bottom, margin.top])
Insert cell
d3.extent(data, (d) => d[0])
Insert cell
r = d3
.scaleSqrt()
.domain(d3.extent(data, (d) => d[1]))
.range([2, 38])
Insert cell
c = d3
.scaleLinear()
.domain(d3.extent(data, (d) => d[1]))
.range(["#022859", "#f20666"])
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