Published
Edited
Sep 21, 2021
Fork of Simple D3
1 star
Insert cell
Insert cell
height = 600
Insert cell
nCircles = 200
Insert cell
xScale = d3.scaleLinear().domain([0, 1.0]).range([0, width])
Insert cell
yScale = d3.scaleLinear().domain([0, 1.0]).range([0, height])
Insert cell
rScale = d3.scaleLinear().domain([0, 1.0]).range([10, 40])
Insert cell
{
const svg = d3.create("svg").attr("width", width).attr("height", height);

for (let i = 0; i < nCircles; i++) {
const x = Math.random();
const y = Math.random();
const r = Math.random();

svg
.append("circle")
.attr("cx", xScale(x))
.attr("cy", yScale(y))
.attr("r", rScale(r))
.attr("fill", getRandomColor())
.attr("stroke", "hsl(216deg 100% 13%)")
.attr("stroke-width", 2);
}

return svg.node();
}
Insert cell
function getRandomColor() {
let color = "#";
for (let i = 0; i < 6; i++) {
color += Math.floor(Math.random() * 16).toString(16);
}
return color;
}
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more