Published
Edited
Jul 18, 2021
Insert cell
Insert cell
title = md`## 內圈高度 = 總投資(HK$)`



Insert cell
title1 = md`## 外圈高度 = 總貨幣化回報(HK$)`
Insert cell
title2 = md`## 弧長 = 項目數目`
Insert cell
chart = {
const svg = d3.select(DOM.svg(width, height))
.attr("viewBox", `${-width / 2} ${-height / 2} ${width} ${height}`)
.style("width", "100%")
.style("height", "auto")
.style("font", "11px sans-serif");

svg.append("g")
.selectAll("g")
.data(d3.stack().keys(data.columns.slice(3))(comboArcs))
.join("g")
.attr("fill", d => z(d.key))
.selectAll("path")
.data(d => d)
.join("path")
.attr("d", arc);

svg.append("g")
.call(xAxis);

svg.append("g")
.call(legend);

return svg.node();
}
Insert cell
Insert cell
data = d3.csvParse(await FileAttachment("SROI final 9@9.csv").text(), (d, _, columns) => {
let total = 0;
for (let i = 1; i < columns.length; ++i) total += d[columns[i]] = +d[columns[i]];
d.total = total;
return d;
})
Insert cell
margin = ({top: 20, right: 0, bottom: 30, left: 40})
Insert cell
arc = d3.arc()
.innerRadius(d => y(d[0]))
.outerRadius(d => y(d[1]))
.startAngle(d => d.data.startAngle)
.endAngle(d => d.data.endAngle -0.01)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
y = {
// This scale maintains area proportionality of radial bars!
const y = d3.scaleLinear()
.domain([0, 1])
.range([innerRadius * innerRadius, outerRadius * outerRadius]);
return Object.assign(d => Math.sqrt(y(d)), y);
}
Insert cell
svg.append("g")
.selectAll("g")
.data(d3.stack().keys(data.columns.slice(3))(comboArcs))
.join("g")
.attr("fill", d => z(d.key))
.selectAll("path")
.data(d => d)
.join("path")
.attr("d", arc);
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
width = 1540
Insert cell
height = width
Insert cell
innerRadius = 129
Insert cell
outerRadius = innerRadius * 2
Insert cell
d3 = require("d3@5")
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more