I am using ObservablePlot (not the base d3, but understanding that ObsPlot uses d3 underneath). I have a beautiful stacked bar chart (cannot show my pic here, will show generic pic below). All looks great except that I need to have totals (sum) of each stacked bar at the top of each stacked bar as in the generic image below.
Not a whole lotta documentation out there on how to do this using ObsPlot. I appreciate any assistance. I am not using Groups, as that did not provide the results we need for the data we have. The below javascript is working perfectly with the exception of the sum (or total) of each stack in each bar.
var plot2 = oPlot.plot({
marginBottom: 5,
width: 928,
height: 500,
x: { label: null },
y: { tickFormat: ".0f", tickSpacing: 20, label: "PRA ($M)", labelAnchor: "center", labelOffset: 40 },
color:
{
legend: "ramp",
width: 540,
label: null,
range: data.Colors
},
marks: [
oPlot.axisX({ ticks: [] }), //to hide xaxis ticks
oPlot.barY(tidy, {
x: "fundType",
y: "total",
insetLeft: 13,
insetRight: 13,
fill: "pra",
sort: { color: null, x: "-y" }
}),
oPlot.textY(
tidy,
oPlot.stackY(
{
x: "fundType",
z: "pra",
y: "total",
text: (d) => (d.total < 50 ? null :
(d.total).toLocaleString("en-US", {
minimumFractionDigits: 0, // Hide cents (if exact dollar).
maximumFractionDigits: 0 // Round to the nearest dollar.
})
),
}
)
)
]
});