Percentage values on my horizontal stacked bar chart gets automatically re-adjusted to a [0, 100]
domain when data is grouped with offset : 'normalize'
(I can see that in the tip by adding "tip: true"
).
Is it possible displaying this calculated value on a dedicated text mark?
Here’s my plot config:
Plot.plot({
width : 800,
height : 600,
marginLeft : 100,
color : {
legend : true
},
x: {
axis : 'bottom',
percent : true,
domain : [0, 100],
ticks : [0, 20, 40, 60, 80, 100]
},
marks: [
Plot.barX(
data,
Plot.groupY({
x : 'proportion',
},
{
y : 'gender',
fill : 'age',
tip : true,
offset : 'normalize'
})
),
Plot.text(
data,
Plot.stackX(
Plot.groupY({
x : 'proportion',
text : (d) => `${((100 * d.length) / total).toFixed(2)} %`, // Need to show the offset value
}, {
z : 'age,
y : 'gender',
fontSize : fontSize,
fontWeight : '500',
offset : 'normalize'
})
)
)
]
})