Trigger callback with clickData in a fig.add_bar

I have a chart that looks like this:


This is the simplified code:

vol_chart = px.line(data_frame = df, x= 'date', y= 'sales_volume' )

vol_chart.add_bar(x= df['date'], y= df['salesman_A'], name="John",  hoverinfo='y')
vol_chart.add_bar(x= df['date'], y= df['salesman_B'], name="Anthony",  hoverinfo='y')

I want to build a new graph that is related to the bars charts. I know how to capture the line graph data with:

hov_year = hov_data['points'][0]['x']

But the bar charts that was created with fig.add_bar I don’t know how to reference in the code.

Is this possible?

Hi, I don’t understand your question. Do you want to reuse code?

Instead of


Your could do:

v = go.Bar()
w = go.Bar()

Hey, I’m using

And I found the answer.

For future references, If you want to get the data of the fig.add bar you just need:

bar_data = hov_data['points'][0]['curveNumber']

curveNumber is the variable you want

then follow by an if condition will do the trick

1 Like