# Select whole column(bar) in stacked bar chart

**URL:** <https://community.plotly.com/t/select-whole-column-bar-in-stacked-bar-chart/70309>\
**Category:** Dash Python\
**Created:** [November 28, 2022, 8:55am UTC](https://community.plotly.com/t/select-whole-column-bar-in-stacked-bar-chart/70309 "2022-11-28T08:55:25Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![AIMPED](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/aimped/32/21758_2.png) [@AIMPED](https://community.plotly.com/u/AIMPED)\
**Post date:** [December 11, 2022, 10:08pm UTC](https://community.plotly.com/t/select-whole-column-bar-in-stacked-bar-chart/70309/5 "2022-12-11T22:08:36Z")

</div>

Hi @Hikari, actually what you are asking for should be an easy task. Because of that, my solution feels wrong: can it really be that complicated to achieve what you want to do?

Anyways, a complicated solution might be preferable over no sloution at all, so here it comes:

I use the click event to get the information, which column has been clicked (`clicked_point`) and use this information for “selecting” all traces at the clicked point.

The code:

```python
from dash import Dash, html, dcc, Input, Output, State
import plotly.express as px

app = Dash( __name__ )

# data
df = px.data.medals_long()

# base figure
fig = px.bar(
    df,
    x="medal",
    y="count",
    color="nation",
    pattern_shape="nation",
    pattern_shape_sequence=[".", "x", "+"]
)

# update clickmode events, enable click event only
fig.update_layout(clickmode='event')

# app layout ( just the graph)
app.layout = html.Div(
    [
        dcc.Graph(
            id='graph',
            figure=fig
        )
    ]
)

@app.callback(
    Output('graph', 'figure'),
    Input('graph', 'clickData'),
    State('graph', 'figure'),
    prevent_initial_call=True
)
def update(data, current_figure):
    # which point has been clicked?
    clicked_point = data["points"][0]["pointIndex"]

    # extract traces
    traces = current_figure['data']

    # loop over all traces
    for idx, trace in enumerate(traces):

        # update selection state of the clicked point in the trace dict
        trace.update({'selectedpoints': [clicked_point]})

        # update figure dict with updated trace dict
        current_figure['data'][idx].update(trace)

    return current_figure

if __name__ == " __main__":
    app.run(debug=True)

```

result:  
 ![bars](https://us1.discourse-cdn.com/flex024/uploads/plot/original/3X/c/b/cb6078b94f7f051d882a7820dd27e6c34409d843.gif)

---

_[View the full topic](https://community.plotly.com/t/select-whole-column-bar-in-stacked-bar-chart/70309)._
