I have 8 different graphs (all time series) in a sub-plot and I am trying to create a vertical line on hover that shows up on all the graphs, which is essentially acting as a crosshair across the different charts.
Currently I have something like this but this only works on one of the subplot graphs.
fig['layout']['xaxis1'].update(rangeslider=dict(visible = False), showspikes= True, spikemode = 'across', spikedash = 'solid', spikecolor = '#A9A9A9', spikethickness=2, spikesnap = 'cursor')
I tried setting up a callback, which saves the x-axis value (the date) and then feed it as an input to create a vertical line shape. However, the issue with this is that in the initial run, there is no hover data so the input id does not exist when feeding it to the graph callback.
@app.callback(
[dash.dependencies.Output('oi_graphs','figure')],
[dash.dependencies.Input('oi_ticker-dropdown', 'value'),
dash.dependencies.Input('oi_hours', 'value'),
dash.dependencies.Input('oi-interval-component', 'n_intervals'),
dash.dependencies.Input('oi-hover-data', 'children')]
)
def oi_create_graph(coin, h,n_update):
.... code that creates the graph ....
oi_hover_line = [{'type': 'line','xref': 'x1','yref': 'y1','x0': hover_date ,'y0': min(df['low']),'x1': hover_date,
'y1': max(df['high']),'opacity': 1,'line': {'width': 1,'color': 'black','dash': 'dot'}}]
@app.callback(
dash.dependencies.Output('oi-hover-data', 'children'),
[dash.dependencies.Input('oi_graphs', 'hoverData')])
def display_hover_data(hoverData):
if hoverData != None:
print("hover data:", hoverData['points'][0]['x'])
return json.dumps(hoverData['points'][0]['x'], indent=2)
else:
return("")