Public
Edited
Nov 28, 2023
Insert cell
Insert cell
Insert cell
{
const svg = d3.create("svg")
.attr("height", 410)
.attr("width", 600);

svg
.append("rect")
.attr("width", 200)
.attr("height", 200)
.style("fill", "#0099cc")
.attr("stroke", "#002db3")
.attr("stroke-width", 4)
.attr("opacity", 0.5);



svg
.append("line")
.attr("x1", 0)
.attr("y1", 200)
.attr("x2", 200)
.attr("y2", 400)
.attr("stroke", "#000099")
.attr("stroke-width", 2);

svg
.append("line")
.attr("x1", 0)
.attr("y1", 400)
.attr("x2", 200)
.attr("y2", 200)
.attr("stroke", "#000099")
.attr("stroke-width", 2)
.attr("opacity", 0.5);
return svg.node();
}
Insert cell
Insert cell
viewof grandezza = Inputs.range([0, 40], {label: "Grandezza", step: 1, value: 20})
Insert cell
{
let svg = d3.create("svg")
.attr("width", 600)
.attr("height", 400)

let gruppo = svg.append("g")

gruppo.append("circle")
.attr("cx", 300)
.attr("cy", 200)
.attr("r", 7 * grandezza)
.attr("fill", "#ffe6cc")

gruppo.append("circle")
.attr("cx", 250)
.attr("cy", 150)
.attr("r", 1 * grandezza)
.attr("fill", "#008ae6")

gruppo.append("circle")
.attr("cx", 350)
.attr("cy", 150)
.attr("r", 1 * grandezza)
.attr("fill", "#008ae6")

gruppo.append("rect")
.attr("y", 230)
.attr("x", 230)
.attr("width", 7 * grandezza)
.attr("height", 2 * grandezza)
.attr("fill", "#cc0000")


return svg.node()
}
Insert cell
Insert cell
{
let svg = d3.create("svg")
.attr("width", 600)
.attr("height", 300);

let data = [
{ x: 60, y: 50, rotation: 0 },
{ x: 120, y: 150, rotation: 25 },
{ x: 250, y: 130, rotation: 100 },
{ x: 45, y: 200, rotation: 80 },
{ x: 430, y: 250, rotation: 280 }
];

let groups = svg.selectAll("g")
.data(data)
.enter()
.append("g")
.attr("transform", d => `translate(${d.x},${d.y}) rotate(${d.rotation})`);


groups.append("rect")
.attr("x", -15)
.attr("y", -10)
.attr("width", 50)
.attr("height", 50)
.attr("fill", "pink")
.attr("stroke", "blue");

return svg.node();
}
Insert cell
Insert cell
viewof numerosità = Inputs.range([50, 200], { label: "numerosità", step: 1 })
Insert cell
{
let svg = d3.create("svg")
.attr("width", 800)
.attr("height", 500);
svg
.append("rect")
.attr("height", 500)
.attr("width", 800)
.attr("fill", "#ff66cc");

for (let i = 0; i < numerosità; i++) {
svg
.append("rect")
.attr("width", 25)
.attr("height", 25)
.attr("x", Math.random() * 800)
.attr("y", Math.random() * 500)
.attr("fill", "#ff3300");
}

return svg.node();
}
Insert cell
Insert cell
carmodels.csv
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
{
let altezza = 500
let marginTop = 20
let marginBottom = 50
let marginLeft = 80
let marginRight = 20
let svg = d3.create("svg")
.attr("height", altezza)
.attr("width", width);

let gruppi = svg.selectAll("g")
.data(cars)
.join("g");

let xScale = d3.scaleLinear()
.range([marginLeft, width - marginRight])
.domain(d3.extent(cars, d=>d["weight (lb)"]));

let yScale = d3.scaleLinear()
.range([altezza - marginBottom, marginTop])
.domain(d3.extent(cars, d=>d["displacement (cc)"]));
gruppi
.attr("transform", (d)=> "translate(" + xScale(d["weight (lb)"]) + ", " + yScale(d["displacement (cc)"]) + ")");

gruppi.append("circle")
.attr("cx", 0)
.attr("cy", 0)
.attr("r", 6)
.attr("fill", "#ff3399")

svg.append("g")
.attr("transform", "translate(0, " + (altezza - marginBottom) + ")")
.call(d3.axisBottom(xScale));

svg.append("g")
.attr("transform", "translate(" + marginLeft + ", 0)")
.call(d3.axisLeft(yScale));

svg.append("text")
.attr("x", width/2)
.attr("y", altezza + 20 - marginBottom/2)
.attr("text-anchor", "middle")
.text("Weight (lb)");

svg.append("text")
.attr("x", marginLeft/2 - 10)
.attr("y", - marginTop + altezza/2)
.attr("text-anchor", "middle")
.attr("transform", "rotate(90, " + (marginLeft / 2 - 10) + ", " + (-marginTop + altezza / 2) + ")") //Per far sì che ruoti su se stesso
.text("Displacement (cc)");
return svg.node()
}
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