<text x="10" y="25" fill="steelblue" font-family="sans-serif" font-size="25">soy un vector con estilo (~_~)//</text>
</svg>
`
html`
<svg width="365", height="${altura}">
<text x="10" y="${altura}" fill="steelblue" font-family="sans-serif" font-size="25">la ge y la jota quedarán cortadas</text>
</svg>
`
random_data={
vardataset=[];
for(vari=0;i<25;i++){
varnuevoNumero=Math.random()*30;
dataset.push(nuevoNumero);
}
returndataset;
}
svg=d3.select(DOM.svg(200,200))
svg.node()
{
constsvg=d3.select(DOM.svg(width,width));//
returnsvg.node();
}
{
//borde del svg
letborder=1
letborderColor="black"
//svg
constsvg=d3.select(DOM.svg(ancho,alto))
.attr("border",border)
//borde del svg
svg.append("rect")
.attr("x",0)
.attr("y",0)
.attr("width",ancho)
.attr("height",alto)
.style("fill","none")
.style("stroke",borderColor)
.style("stroke-width",border);
//rectágulos para visualizar datos
svg.selectAll("rect")
.data(datos)
.enter().append("rect")
.attr("x",0)
.attr("y",(d,i)=>ancho-20*(i+1)-i)
.attr("width",(d)=>d)
.attr("height",20);
//dibujar
returnsvg.node();
}
{
constsvg=d3.select(DOM.svg(ancho,alto))
.attr("border",border)
varborder=1
varborderColor="black"
svg.append("rect")
.attr("x",0)
.attr("y",0)
.attr("width",ancho)
.attr("height",alto)
.style("fill","none")
.style("stroke",borderColor)
.style("stroke-width",border);
svg.append("g")
.attr("fill","steelblue")
.selectAll("rect")
.data(datos)
.enter().append("rect")
.attr("x",0)
.attr("y",(d,i)=>ancho-20*(i+1)-i)
.attr("width",(d)=>d)
.attr("height",20);
returnsvg.node();
}
x=d3.scaleLinear()
.domain([0,70])
.range([0,ancho])
{
constsvg=d3.select(DOM.svg(ancho,alto))
.attr("border",border)
varborder=1
varborderColor="black"
svg.append("rect")
.attr("x",0)
.attr("y",0)
.attr("width",ancho)
.attr("height",alto)
.style("fill","none")
.style("stroke",borderColor)
.style("stroke-width",border);
letanchoBin=alto/datos.length;
svg.append("g")
.attr("fill","steelblue")
.selectAll("rect")
.data(datos)
.enter().append("rect")
.attr("x",0)
.attr("y",(d,i)=>ancho-anchoBin*(i+1)-i)
.attr("width",(d)=>x(d))
.attr("height",anchoBin);
returnsvg.node();
}
margen=({
izquierda:30,
derecha:0
})
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.