HI,
Basically i want to sync the scale of the timeseries graphs bidirectionly by changing the layout xaxis and yaxis ranges based of the relayoutdata of the other graph, But i cant seem to understand why my graph doesnt update the layout nor i the both graphs stops showing the ploted data
@app.callback(
Output('timeseries-graph', 'figure',allow_duplicate=True),
Output('timeseries-graph2', 'figure',allow_duplicate=True),
Input('timeseries-graph', 'relayoutData'),
Input('timeseries-graph2', 'relayoutData'),
State('timeseries-graph', 'figure'),
State('timeseries-graph2', 'figure'),
prevent_initial_call=True
)
def sync_graphs(relayoutData1, relayoutData2, fig1, fig2):
new1=fig1
new2=fig2
ctx = dash.callback_context
print(ctx.triggered)
if not ctx.triggered:
return new1, new2
if fig1 is None or fig2 is None:
print('retornou None')
return new1, new2
triggered_id = ctx.triggered[0]['prop_id'].split('.')[0]
if triggered_id == 'timeseries-graph' and relayoutData1:
if 'xaxis.range[0]' in relayoutData1 and 'xaxis.range[1]' in relayoutData1:
x0 = relayoutData1['xaxis.range[0]']
x1 = relayoutData1['xaxis.range[1]']
new2['layout']['xaxis'] = fig2['layout'].get('xaxis', {})
new2['layout']['xaxis'] = {'range':(x0, x1),'autorange':False}
if 'yaxis.range[0]' in relayoutData1 and 'yaxis.range[1]' in relayoutData1:
y0 = relayoutData1['yaxis.range[0]']
y1 = relayoutData1['yaxis.range[1]']
new2['layout']['yaxis'] = fig2['layout'].get('yaxis', {})
new2['layout']['yaxis'] = {'range':(y0, y1),'autorange':False}
if triggered_id == 'timeseries-graph2' and relayoutData2:
if 'xaxis.range[0]' in relayoutData2 and 'xaxis.range[1]' in relayoutData2:
x0 = relayoutData2['xaxis.range[0]']
x1 = relayoutData2['xaxis.range[1]']
new1['layout']['xaxis'] = fig1['layout'].get('xaxis', {})
new1['layout']['xaxis'] = {'range':(x0, x1),'autorange':False}
if 'yaxis.range[0]' in relayoutData2 and 'yaxis.range[1]' in relayoutData2:
y0 = relayoutData2['yaxis.range[0]']
y1 = relayoutData2['yaxis.range[1]']
new1['layout']['yaxis'] = fig1['layout'].get('yaxis', {})
new1['layout']['yaxis'] = {'range':(y0, y1),'autorange':False}
print(new1)
print(x0,x1)
return new1, new2
after some debugging i verified that new 1 is a valid dict with all the data point it should have and with the right ranges, but when i return it, it doesnt really show it.
here is dash layout of that part:
dcc.Graph(id='timeseries-graph',
style={'height': '350px'},
config={'scrollZoom': True,'displaylogo':False},
loading_state={'is_loading ':True}
),
dcc.Graph(id='timeseries-graph2',
style={'height': '350px', 'margin-top': '-40px'},
config={'scrollZoom': True,'displaylogo':False}
),
html.Span(id='info graph',
children=''),
html.Span(id='info graph2',
children='')
])
Any tips for fixing it? I can provide any info if needed.
Thanks in advance!