Hi All,
I was wondering whether it was possible to get the ‘name’ attribute of stacked bar charts. (or get acces to the entire trace)
In the example below I have a stacked barchart for two names (‘Ajax’ and ‘Feyenoord’), and when
the users clicks on the graph I would like to know whether they clicked on the Ajax or Feyenoord portion.
Instead the clickData output looks like this: { "points": [ { "curveNumber": 0, "pointNumber": 1, "pointIndex": 1, "x": 2, "y": 20 }, { "curveNumber": 1, "pointNumber": 1, "pointIndex": 1, "x": 2, "y": 30 } ] }
, which both doesn’t show the name and simply shows the stack of datapoints for that stack of the barchart.
Code below.
import dash
from dash.dependencies import Input, Output, State
import dash_html_components as html
import dash_core_components as dcc
import json
import plotly.plotly as py
import plotly.graph_objs as go
app = dash.Dash(__name__)
data = [
dict(x=[1,2], y=[10,20], name='Ajax', text='Ajax', type='bar'),
dict(x=[1,2], y=[40,30], name='Feyenoord', test='Feyenoord', type='bar'),
]
layout = dict(title='test graph',
xaxis=dict(title='AB'),
yaxis=dict(title='number'),
barmode='relative',
showlegend=True)
fig = dict(data=data, layout=layout)
app.layout = html.Div([
dcc.Graph(
id='graph',
figure = fig
),
html.Div(id='clickData_out')
])
@app.callback(
Output('clickData_out', 'children'),
[Input('graph', 'clickData')])
def display_click_data(clickData):
return json.dumps(clickData, indent=2)
if __name__ == '__main__':
app.run_server(debug=True)