Published
Edited
Dec 17, 2018
1 fork
3 stars
Insert cell
md`# Progress Bar`
Insert cell
Insert cell
htmlElement = html`<div id="htmlSpace"></div>`
Insert cell
Insert cell
Insert cell
Insert cell
margin = { return {top:50, right: 20, bottom: 30, left: 40} }
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
x = d3.scaleLinear().range([0, width])
Insert cell
y = d3.scaleBand().range([height, 0]).padding(0.1)
Insert cell
Insert cell
Insert cell
y.domain(data.map((d) => { return d.salesperson }))
Insert cell
svg.selectAll(".bar").data(data).enter().append("rect").attr("class", "bar").attr('rx', 5).attr('ry', 5).attr('x', 0).attr("width", (d) => { 0 } ).attr("y", (d) => { return y(d.salesperson); } ).attr('height', 10).attr('transform', 'translate(' + 0 + ',' + ((y.bandwidth()/2)- 5) + ')').transition().duration(1500).delay((d, i) => { return i*250 }).attr('width', (d) => { return x(d.sales) }).attr('fill', (d,i) => { return colorScheme[i] } )
Insert cell
svg.selectAll("bar-background").data(data).enter().append("rect").attr("class", "bar-background").attr('rx', 5).attr('ry', 5).attr("width", width).attr("y", (d) => { return y(d.salesperson); } ).attr('height', 10).attr('transform', 'translate(' + 0 + ',' + ((y.bandwidth()/2)- 5) + ')').attr('fill', '#EBEBEB')
Insert cell
// svg.append("g").attr('transform', "translate(0 " + ',' + height + ')').attr('class', "x axis").call(d3.axisBottom(x))
Insert cell
// svg.append('g').attr('class', 'y axis').call(d3.axisLeft(y))
Insert cell
Insert cell
svg.selectAll('name').data(data).enter().append('text').attr('class', 'name').text((d) => {
return d.salesperson }).attr('x',0).attr('y', (d) => { return y(d.salesperson) }).attr('transform', 'translate(' + 0 + ',' + ((y.bandwidth()/2) - 15) + ')')
Insert cell
svg.selectAll('value').data(data).enter().append('text').attr('class', 'value').text((d) => {
return d.sales}).attr('x', width - margin.left).attr('y', (d) => { return y(d.salesperson) }).attr('transform', 'translate(' + 0 + ',' + ((y.bandwidth()/2) - 15) + ')')
Insert cell
Type JavaScript, then Shift-Enter. Ctrl-space for more options. Arrow ↑/↓ to switch modes.

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