I am using plot.ly to display the in_time and out_time in respective dates. i used pandas to extract the data frame and fed to the plotly to display the line graph but the problem is that the time displayed in y axis is not sorted and the time data is mixed up
def get_emp_graph(e_id): tls.set_credentials_file(username='XXXXX', api_key='YYYYYY')
df = pd.DataFrame(list(AttendanceRecord.objects.filter(emp_id=e_id, ).values().order_by('date')))
df['in_time'] = df['in_time'].apply(lambda x: format(datetime.strptime(x, '%H:%M:%S'), '%H:%M:%S'))
df['out_time'] = df['out_time'].apply(lambda x: format(datetime.strptime(x, '%H:%M:%S'), '%H:%M:%S'))
df['date'] = df['date'].apply(lambda x: datetime.strptime(x, '%Y-%m-%d').date())
df['miti'] = df['miti'].apply(lambda x: datetime.strptime(x, '%Y/%m/%d').date())
print(df['in_time'])
print(df['date'])
trace1 = go.Scatter(
x=df['date'],
y=df['in_time'],
name='In Time',
mode='markers+lines',
text=e_id,
line=dict(color='#17BECF'),
)
trace2 = go.Scatter(
x=df['date'],
y=df['out_time'],
name='Out Time',
mode='markers+lines',
text=e_id,
line=dict(color='#7F7F7F'),
)
data = [trace1, trace2]
layout = go.Layout(title="Time Analysis", showlegend=True,yaxis=dict(autorange=True))
fig = go.Figure(data=data, layout=layout)
div = plt.plot(fig, filename='d3', auto_open=False)
print(div)
return div