Rangebreaks: adding date issue; chart is not loaded

Hi there,

i am facing this weird issue. When I add “2024-05-20” to the dict values inside rangebreaks, the chart does not load at all. But with other dates like dict(values=[“2024-12-25”, “2024-12-24”]) chart loads normally and everything’s fine.

What am I missing here? Thanks for your help.

@app.callback(
     Output('candlestick-chart', 'figure'),
     [Input('active-ticker-store', 'data'),
      Input('candlestick-update-interval', 'n_intervals'),
      Input('hovermode', 'value'),
      Input('resample-dropdown', 'value')],
     [State('candlestick-chart', 'relayoutData'),
      State('candlestick-chart', 'figure')]
 )
 def update_candlestick_chart(active_ticker_data, n_intervals, hovermode, resample_value, relayoutData, figure):
     ticker = active_ticker_data['ticker']
     df, _, dt_breaks = get_hist(ticker, resample_value)  # Pass the resample value to get_hist
     #print(f'df = {df}')
     if df.empty:
         return go.Figure()
 
     y_min = df['buy-sell_EMA_low'].min()
     y_max = df['buy-sell_EMA_high'].max()
 
     # Conditionally set hovertemplate based on hovermode
     hovertext = '%{x}' if hovermode == 'x' else '%{x}<br>Open: %{open}<br>High: %{high}<br>Low: %{low}<br>Close: %{close}'
 
     # Create the candlestick chart
     fig = go.Figure(data=[go.Candlestick(
         x=df.index,
         open=df['buy-sell_EMA_open'],
         high=df['buy-sell_EMA_high'],
         low=df['buy-sell_EMA_low'],
         close=df['buy-sell_EMA_close'],
         increasing_line_color='green', 
         decreasing_line_color='red',
         hovertext=hovertext
     )])
 
     # Apply the relayout data if it exists and ticker has not changed
     if relayoutData and figure and figure['layout']['uirevision'] == ticker:
         if 'xaxis.range[0]' in relayoutData:
             fig.update_layout(xaxis_range=[relayoutData['xaxis.range[0]'], relayoutData['xaxis.range[1]']])
         if 'yaxis.range[0]' in relayoutData:
             fig.update_layout(yaxis_range=[relayoutData['yaxis.range[0]'], relayoutData['yaxis.range[1]']])
     else:
         # Reset y-axis range if ticker changes
         fig.update_layout(yaxis_range=[y_min, y_max])
 
     # Customize layout to include crosshairs with labels at the end
     fig.update_layout(
         title=dict(text=f'{ticker}: Candlestick Chart', font=dict(size=30)),
         xaxis_title=dict(text='Time', font=dict(size=22)),
         yaxis_title=dict(text='Price', font=dict(size=22)),
         xaxis_rangeslider_visible=False,
         hovermode=hovermode,  # Dynamic hovermode based on radio button selection
         xaxis=dict(
             type='date',
             title_font=dict(size=20),
             rangebreaks=[
                 dict(bounds=["fri", "mon"]),  # hide weekends
                 dict(bounds=[16, 9], pattern="hour"),  # hide hours outside of 9am-4pm
                 dict(values=["2024-12-25", "2024-12-24"])  # hide holidays "2024-05-20",
             ],
             showspikes=True,
             spikemode='across',
             spikesnap='cursor',
             spikedash='solid',
             spikethickness=2,
             showline=True,
             showgrid=False,
             fixedrange=False  # Ensure zooming is enabled
         ),
         yaxis=dict(
             title_font=dict(size=20),
             autorange=True,
             showspikes=True,
             spikemode='across',
             spikesnap='cursor',
             spikedash='solid',
             spikethickness=2,
             showline=True,
             showgrid=False,
             fixedrange=False  # Ensure zooming is enabled
         ),
         plot_bgcolor='black',
         paper_bgcolor='black',
         font_color='white',
         font=dict(
             family="Arial, sans-serif",
             size=20,
             color="white"
         ),
         hoverlabel=dict(
             bgcolor="white",
             font_size=16,
             font_family="Arial"
         ),
         dragmode='pan',        
         uirevision=ticker,
     )
 
     return fig

Ensure that the date format you’re adding matches the date format of your DataFrame’s index. If there’s a mismatch, Plotly might not recognize the date correctly. Check if there is data for the date “2024-05-20” in your DataFrame. If there’s no data for this date, it might cause issues when Plotly tries to render the chart. There might be a syntax error or a missing comma when adding the date to the rangebreaks. Make sure the list of dates is properly formatted.

xaxis=dict(
type=‘date’,
title_font=dict(size=20),
rangebreaks=[
dict(bounds=[“fri”, “mon”]), # hide weekends
dict(bounds=[16, 9], pattern=“hour”), # hide hours outside of 9am-4pm
dict(values=[“2024-12-25”, “2024-12-24”, “2024-05-20”]) # hide holidays
],
showspikes=True,
spikemode=‘across’,
spikesnap=‘cursor’,
spikedash=‘solid’,
spikethickness=2,
showline=True,
showgrid=False,
fixedrange=False # Ensure zooming is enabled
)