How can I use plotly in django project to make bar graph?

Hi guys I am working on python django dashboard work using plotly , and this is ticket booking app, in this dashboard i need to show the count of tickets in bar graph, in this i need to show the tickets in month wise ,in that in every bar i need to show the ticket count of every event in different colour ,how can i do this ? Please give any idea. I add the code also

def dashboard(request):
df_gapminder =

events = event_master.objects.all()
data = []
for event in events:
    event_data = {
        'text': f"{event.Event_Name} - {event.Event_Description} - {event.Start_Date}",

selected_event_id = request.GET.get('event_id')
selected_event = None
if selected_event_id:
    selected_event = event_master.objects.get(id=selected_event_id)
    ticket_data = ticket_information.objects.values('event_master_id').filter(
    ticket_data = ticket_information.objects.values('event_master_id').annotate(ticket_count=Count('id'))

event_data = event_master.objects.values('id', 'Start_Date')
ticket_df = pd.DataFrame.from_records(ticket_data)
event_df = pd.DataFrame.from_records(event_data)
merged_df = ticket_df.merge(event_df, left_on='event_master_id', right_on='id', how='left')
merged_df['Start_Date'] = pd.to_datetime(merged_df['Start_Date'])
merged_df['Month'] = merged_df['Start_Date'].dt.strftime('%Y-%m')

fig = go.Figure()

if selected_event:
    event_ticket_count = merged_df[merged_df['event_master_id'] ==]
        go.Bar(x=[selected_event.Start_Date.strftime('%Y-%m')], y=[event_ticket_count['ticket_count'].sum()],
               name=selected_event.Event_Name, text=[selected_event.Event_Name],
               textposition='inside', marker_color='steelblue'))
        title=f'Ticket Count for {selected_event.Event_Name}',
        yaxis_title='Ticket Count'
    monthly_ticket_count = merged_df.groupby('Month')['ticket_count'].sum().reset_index()
    fig = go.Figure(data=[go.Bar(x=monthly_ticket_count['Month'], y=monthly_ticket_count['ticket_count'],
                                text=monthly_ticket_count['ticket_count'], textposition='inside',
        title='Ticket Count by Month',
        yaxis_title='Ticket Count'

fig.update_traces(marker_line_color='rgb(8,48,107)', marker_line_width=1.5)
fig.update_layout(uniformtext_minsize=8, uniformtext_mode='hide')

chart_html = fig.to_html(full_html=False, include_plotlyjs='cdn')
return render(request, 'K_Ticket/EventDashboard.html',
              {'chart_html': chart_html, 'data': data, 'selected_event': selected_event})

And i give you one sample code i get in plotly website but it is wrote in jupyter notebook but i need the same requirement in django project.

sample code:
import as px
df =

fig =, x=“medal”, y=“count”, color=“nation”, text_auto=True)

Take a look at django-plotly-dash - this allows you to embed dash applications as template tags.

You will have to write a Django view to pass parameters to the app, such as your event_id parameter; you might find it advantageous to pass that as part of the URL.