Black Lives Matter. Please consider donating to Black Girls Code today.

All bars not selecting at a time

Hi All

I am anticipating bar selection of my plot like this

But, Somehow I am only able to do this

Here each colored bar is rendered as one trace so total three traces.

How can I resolve this?

Any help will be appreciated.
TIA

Tia, can you share your code with us?

This is the snippet which renders this plot:

def return_bar():
   years = df['Year'].unique().tolist()
   categories = df['Categories'].unique().tolist()
   y1 = df['Total'][df['Categories']==categories[0]].tolist()
   y2 = df['Total'][df['Categories']==categories[1]].tolist()
   y3 = df['Total'][df['Categories']==categories[2]].tolist()

   fig = go.Figure(data=[
    go.Bar(name='Cat 1', x=years, y=y1,legendgroup='Cat 1'),
    go.Bar(name='Cat 2', x=years, y=y2,legendgroup='Cat 2'),
    go.Bar(name='Cat 3', x=years, y=y3,legendgroup='Cat 3')
   ])

   # Change the bar mode
   fig.update_layout(margin= {'l': 0, 'r': 0, 't': 0, 'b': 0},xaxis=dict(automargin=True,title='Years'),yaxis=dict(automargin=True,title='XAXIS TITLE'),
   clickmode="event+select",barmode='group',legend_orientation="h",legend_title={'side':'top','text':'<b>Categories</b>'})
   return fig

I tried to manipulate this using callback and I was able to achieve this partially. I was able to manipulate all other bars to selected bar categories but was not able to unselect all.

Any help on this would be appreciated.

This is the code snippet for the callback.

@app.callback(
    dash.dependencies.Output('bar','figure'),
    [dash.dependencies.Input('bar','selectedData')],
    state=[dash.dependencies.State('bar','figure')])

def update(selectedData,figure):
    if figure['data'][0]['name'] == 'Cat 1':
        if figure['data'][0]['selectedpoints'] == [0]:
                figure['data'][0]['selectedpoints'] = [0,1,2,3,4]
1 Like