Published
Edited
Jun 18, 2019
Insert cell
Insert cell
chart = {
const svg = d3.select(DOM.svg(width, height));
svg.append("g")
.attr("fill", "steelblue")
.selectAll("rect")
.data(data)
.join("rect")
.attr("x", x(0))
.attr("y", d => y(d.name))
.attr("width", d => x(d.percent) - x(0))
.attr("height", y.bandwidth());
svg.append("g")
.attr("fill", "white")
.attr("text-anchor", "middle")
.style("font", "12px sans-serif")
.selectAll("text")
.data(data)
.join("text")
.attr("x", d => x(d.percent) / 2 + 15)
.attr("y", d => y(d.name) + y.bandwidth() / 2)
.attr("dy", "0.35em")
.text(d => d.name);
svg.append("g")
.attr("fill", "black")
.attr("text-anchor", "after-edge")
.style("font", "12px sans-serif")
.selectAll("text")
.data(data)
.join("text")
.attr("x", d => x(d.percent) + 5)
.attr("y", d => y(d.name) + y.bandwidth() / 2)
.attr("dy", "0.35em")
.text(d => d.value);
return svg.node();
}
Insert cell
data = new Object([{
"name": "Deviation from Profile Expectations",
"percent": 47,
"value": 116
}, {
"name": "Suspicious Trade Activity",
"percent": 26,
"value": 64
}, {
"name": "High Risk Terms",
"percent": 16,
"value": 40,
}, {
"name": "Structuring",
"percent": 11,
"value": 26,
}]);
Insert cell
format = x.tickFormat(20)
Insert cell
x = d3.scaleLinear()
.domain([0, d3.max(data, d => d.value)])
.range([margin.left, width - margin.right])
Insert cell
y = d3.scaleBand()
.domain(data.map(d => d.name))
.range([margin.top, height - margin.bottom])
.padding(0.1)
Insert cell
xAxis = g => g
.attr("transform", `translate(0,${margin.top})`)
.call(d3.axisTop(x).ticks(width / 80))
.call(g => g.select(".domain").remove())
Insert cell
yAxis = g => g
.attr("transform", `translate(${margin.left},0)`)
.call(d3.axisLeft(y).tickSizeOuter(0))
Insert cell
height = data.length * 25 + margin.top + margin.bottom
Insert cell
margin = ({top: 30, right: 0, bottom: 10, left: 30})
Insert cell
d3 = require("d3@5")
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