plot = Plot.plot({
marks: [
Plot.barX(
[
{group: "total", type: "社会价值", value: total.social},
{group: "total", type: "灵魂价值", value: total.soul},
{group: "total", type: "未实现", value: total.remaining}
],
{
y: "group",
x: "value",
fill: "type",
stack: true
}
),
Plot.text(
[{group: "total", x: total.social/2, text: `社会价值 ${total.social.toFixed(1)}`}],
{
y: "group",
fill: "white",
fontWeight: "bold"
}
),
Plot.text(
[{group: "total", x: total.social + total.soul/2, text: `灵魂价值 ${total.soul.toFixed(1)}`}],
{
y: "group",
fill: "white",
fontWeight: "bold"
}
)
],
color: {
domain: ["社会价值", "灵魂价值", "待实现"],
range: ["#1f77b4", "#ff7f0e", "#e0e0e0"],
legend: true
},
y: {axis: null},
x: {domain: [0, 100], label: "加权总分"},
width: 600,
height: 100,
marginBottom: 40
})