Hello all,
m currently making an applicaton to list the downtime of machines that are not working.I’m getting the result where the x is showed as numeric values.My project manager would like that the numeric values be changed to day,week and month under bar of the exact date ie.When I unout the start date from 01.08.2021 to 09.08.2021 that under every bar is showed the time like 06.08.2021 now it only shows like 1,2,3 per bar.Do you have any info how I can make it work?
this is the picture how it looks atm.
this is my code atm:
@app.callback(
Output("bar_chart7", "figure"),
#[
#Output("table1", "data"),
##Output("Bar_chart_link", "children"),
#Output("bar7", "children")
#]
[Input("downtime_data", "data")],
state=[State("start_date_picker", "date"),
State("start_time_picker", "value"),
State("end_date_picker", "date"),
State("end_time_picker", "value"),
State("database", "value"),
State("language", "value")]
)
def create_bar_chart(n_clicks, start_date_picker, start_time_picker, end_date_picker, end_time_picker, database, language):
if n_clicks:
start_time = datetime.datetime.strptime(start_date_picker, "%Y-%m-%d") + datetime.timedelta(hours=int(start_time_picker[0:2]))
end_time = datetime.datetime.strptime(end_date_picker, "%Y-%m-%d") + datetime.timedelta(hours=int(end_time_picker[0:2]))
parameters = [start_time, end_time]
# if not n_clicks:
# db_query_string = """"SELECT NotificationLog.ID as 'ID',
# DAY(Timestamp) as 'DAY',
# MONTH(Timestamp) as 'MONTH',
# NotificationLog.Duration,
# DATEPART(WEEK, NotificationLog.Timestamp)-1 as 'Week Number'
# FROM NotificationLog
# BETWEEN ? AND ?"""
query_string = mssql_queries.build_db_query_app7()
records = mssql_conn.execute_query(query_string, parameters, str(database))
if records:
dataframe = pd.DataFrame.from_records(records)
dataframe.columns = ["ID", "DAY", "MONTH", "Duration", "Week Number"]
# dataframe = dataframe.groupby('Week Number')['Duration'].sum().reset_index()
dataframe = dataframe.groupby('DAY')['Duration'].sum().reset_index()
dataframe['Duration'] = dataframe['Duration'].apply(lambda x: x/60)#pretvoriti u sekunde
#dataframe['Duration'] = dataframe['Duration'].astype('datetime64[s]').dt.strftime("%H:%M:%S")#pretvoriti u minute
# trace1 = go.Bar(name="Down_Time_In_Min", x=dataframe["Duration"], y=dataframe["Down Time In Min"], marker=dict(color='rgb(34,163,192)'))
print("--dataframe--")
print(dataframe)
print("---")
# layout = go.Layout(
# font=go.Font(
# color='rgb(128,128,128)',
# family='Balto, sans-serif',
# size=12
# ),
# height=800,
# paper_bgcolor='rgb(240,240,240',
# plot_bgcolor='rgb(240,240,240)',
# )
# mask = dataframe.applymap(type) != bool
# d = {True: "1", False: "0"}
# dataframe = dataframe.where(mask, dataframe.replace(d))
# print("----")
# print(dataframe)
#layout = go.Layout(
#title='Consumer Financial Protection Bureau: Consumer Complaints',
#titlefont=dict(
# color='rgb(128,128,128)',
# family='Balto, sans-serif',
# size=12
#),
#font=go.Font(
# color='rgb(128,128,128)',
# family='Balto, sans-serif',
# size=12
#),
#width=1770,
#height=800,
#paper_bgcolor='rgb(240, 240, 240)',
#plot_bgcolor='rgb(240, 240, 240)',
#
#)
# fig = px.bar(dataframe, x=dataframe['Week Number'], y=dataframe['Duration'])
fig = px.bar(dataframe, x=dataframe['DAY'], y=dataframe['Duration'])
#fig.show()
return go.Figure(fig)
#return dbc.Table.from_dataframe(dataframe), dataframe.to_json(date_format="iso", orient="split"), None