Public
Edited
Apr 2
Insert cell
Insert cell
md`Re-create the above graphic using D3.`
Insert cell
<svg width="100" height="100">
<g transform="translate(50, 50)">
<circle r="50" fill="steelblue"/>
<text fill="white" font-size="50" dominant-baseline="middle" text-anchor="middle">vis</text>
</g>
</svg>
Insert cell
// tu código 1
{
const svg = d3.create("svg")
.attr("width", 100)
.attr("height", 100);

const g = svg.append("g")
.attr("transform", "translate(50, 50)");

g.append("circle")
.attr("r", 50)
.attr("fill", "steelblue");

g.append("text")
.attr("fill", "white")
.attr("font-size", 50)
.attr("dominant-baseline", "middle")
.attr("text-anchor", "middle")
.text("vis");

return svg.node();
}


Insert cell
Insert cell
segments = [ //1
{ x1: 5, y1: 5, x2: 5, y2: 95 },
{ x1: 45, y1: 5, x2: 45, y2: 95 },
{ x1: 5, y1: 95, x2: 45, y2: 95 },
{ x1: 60, y1: 5, x2: 100, y2: 5 },
{ x1: 80, y1: 5, x2: 80, y2: 95 },
{ x1: 115, y1: 5, x2: 115, y2: 95 },
{ x1: 115, y1: 5, x2: 145, y2: 5 },
{ x1: 115, y1: 50, x2: 140, y2: 50 },
{ x1: 115, y1: 95, x2: 145, y2: 95 },
{ x1: 160, y1: 5, x2: 190, y2: 5 },
{ x1: 160, y1: 5, x2: 160, y2: 95 },
{ x1: 160, y1: 95, x2: 190, y2: 95 },
];
Insert cell
{
const svg = d3.create('svg')
.attr('width', 200)
.attr('height', 100);
//código
svg.selectAll('line')
.data(segments)
.join('line')
.attr('x1', d => d.x1)
.attr('y1', d => d.y1)
.attr('x2', d => d.x2)
.attr('y2', d => d.y2)
.attr('stroke', 'black');

return svg.node();
}
Insert cell
Insert cell
Insert cell
iris = require('@observablehq/iris')
Insert cell
iris
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
Insert cell
widthIris = 400
Insert cell
heightIris = 400
Insert cell
Insert cell
Insert cell
sepalWidthMin = d3.min(iris, d => d.sepalWidth)
Insert cell
sepalWidthMax = d3.max(iris, d => d.sepalWidth)
Insert cell
Insert cell
xIris = d3.scaleLinear()
.domain([sepalLengthMin, sepalLengthMax])
.range([0, widthIris])
Insert cell
Insert cell
sepalLengthMin = d3.min(iris, d => d.sepalLength)
Insert cell
sepalLengthMax = d3.max(iris, d => d.sepalLength)
Insert cell
yIris = d3.scaleLinear()
.domain([sepalWidthMin, sepalWidthMax])
.range([heightIris, 0])
Insert cell
Insert cell
species = Array.from(new Set(iris.map(d => d.species)))
Insert cell
Insert cell
colorIris = d3.scaleOrdinal()
.domain(species)
.range(d3.schemeCategory10)
Insert cell
Insert cell
//Código aqui 3 puntos
scatterplot = {
const svg = d3.create("svg")
.attr("width", widthIris + 10)
.attr("height", heightIris + 10);
svg.selectAll("circle")
.data(iris)
.join("circle")
.attr("cx", d => xIris(d.sepalLength))
.attr("cy", d => yIris(d.sepalWidth))
.attr("fill", d => colorIris(d.species))
.attr("r", 3);

return svg.node();
}


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