Public
Edited
Mar 22, 2023
Fork of Simple D3
Insert cell
Insert cell

chart = {

const center = [width / 2, height / 2];

const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);
const node = svg.append("g")
.selectAll("circle")
.data(data)
.join("circle")
.attr("r", d => d.radius)
.attr("fill", d => d.color);

const simulation = d3.forceSimulation(data)
.on('tick', tick)
.force("collide", d3.forceCollide().radius(d => 1 + d.radius))
.force("x", d3.forceX(center[0]).strength(0.001))
.force("y", d3.forceY(center[1]).strength(0.001))
.stop();

function tick() {
node.attr("cx", d => d.x).attr("cy", d => d.y);

};


tick();

return svg.node();
}
Insert cell
height = 400
Insert cell
width = 400
Insert cell
data = d3.range(50).map(x => ({id: x, x: 0, y: 0, radius: Math.random() * 50}))
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