// create our outer SVG element with a size of 500x100 and select it
constsvg=d3.create('svg')
.attr('width',500)
.attr('height',100);
// create one bar for each element in scores
constbars=svg.selectAll('rect')
.data(scores)
.join('rect')
// set the attributes for the rects
.attr('fill','steelblue')
.attr('x',0)
.attr('y',0)// EDIT THIS LINE
.attr('width',0)// EDIT THIS LINE
.attr('height',0)// EDIT THIS LINE
// return the outer SVG element in order to render it
returnsvg.node();
}
ordinalScale=d3.scaleOrdinal()
.domain(['one','two','three'])
.range([1,2,3])
ordinalScale('one')
ordinalScale('two')
ordinalScale('three')
names
color=d3.scaleOrdinal()
.domain(names)
.range(['red','blue','green','pink','purple'])
{
// create our outer SVG element with a size of 500x100 and select it
constsvg=d3.create('svg')
.attr('width',500)
.attr('height',100);
// create one bar for each element in scores
constcircles=svg.selectAll('rect')
.data(scores)
.join('rect')
// set the attributes for the rects
.attr('fill','steelblue')// EDIT THIS LINE
.attr('x',0)
.attr('y',d=>y(d.name))
.attr('width',d=>x(d.score))
.attr('height',y.bandwidth())
// return the outer SVG element in order to render it
returnsvg.node();
}
d3=require('d3@6')
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.