I want to format the hover information so that it shows the absolute value. For example, when hovering over a bar in the “men” series, i want the absolute value, not the negative value.
I figured this out.
To create the negative bars, the data for men, I multiplied the series by -1. To get positive hover values, I added the original data array to “customdata”. See the revised trace below:
trace1 = {
name: 'men',
type: 'bar',
x: pct_male_0, //this is the negative number array
y: age_arr,
customdata : pct_male_0d, //this is the positive number array
hovertemplate : 'Men : %{customdata:0.1%}',
marker: {
color : 'white',
line: {
opacity : 1,
color: 'black',
width: 2
} },
orientation: 'h'
};