Hello Community
I’m trying to plot two different series (i.s. imported qty and unit price) in the same figure across time and switch them with the button. I have tried with updatemenus.
but, the button only updates the series and does not update the label of the y-axis as well as the hover text of the series. How can I do that?
and 2nd question:
I have a list of importers, so I wanted to set a drop-down on this chart and add a line for each importer for both series (i.e. importer_qty and unit price).
I’m new to dash and plotly.
Thank You.
dfx = pd.DataFrame({'months':['apr','may','jun','jul','aug','sep','oct','nov','dec','jan','feb','mar']
,'imported_qty':[25,35,45,30,35,45,50,25,30,35,45,40]
,'unit_price':[1.80,1.75,2.10,2.08,2.25,2.20,2.35,2.38,2.28,2.32,2.38,2.51]})
fig = px.line(dfx, x='months', y=dfx['imported_qty'])
fig.update_traces(mode="lines")
fig.update_layout(yaxis={'showgrid': False}
,xaxis={'showgrid': False}
,template='plotly_dark'
,hovermode="x"
,legend=dict(y=1, x=1, font=dict(size=8))
,height=350
,font=dict(size=10, color='gray')
,title={'text': "Chips Import Trend"
,'y':0.95
,'x':0.5
,'xanchor': 'center'
,'yanchor': 'top'
,'font_size':15
,'font_color':'white'}
,updatemenus=[
dict(
type="buttons",
direction="right",
x=0.7,
y=1,
showactive=True,
buttons=list(
[
dict(
label="Qty",
method="update",
args=[{"y": [dfx['imported_qty']]}
,{'title':'Chips Import Trend'}
,{'y':'Import qty.'}],
),
dict(
label="Price",
method="update",
args=[{"y": [dfx['unit_price']]}
,{'title':'Chips Unit Price Trend'}
,{'y':'Unit Price'}],
),
]
),
)
]
)
fig.update_yaxes(color='white')
fig.update_xaxes(color='white')