Hello I have the following problem
When trying to set a “base” in a barplot i.e I want bar k span between value i and j
but all I get is that bar k span from the start of the bar with lowest base…
To exemplify, here is my example data
Event Finish Start Unit
0 Active 2010-01-01 15:00:00 2010-01-01 01:00:00 Unit1
1 Active 2010-01-01 16:00:00 2010-01-01 05:00:00 Unit2
2 Active 2010-01-01 17:00:00 2010-01-01 07:00:00 Unit3
bar 0 span from start0 to finish0, no problem
bar 1 span from start0 to finish1, problem
etc…
The purpose is to make something similar to a gantt scheme and I’ve tried create_gantt from figure factory
but it did not quite fulfilled my demands.
The following code is used to reproduce the problem and are an part of a larger code but enough for reproduce…
Thank you!
import dash
import dash_core_components as dcc
import dash_html_components as html
import plotly.graph_objs as go
import pandas as pd
#simulated active
unit = [‘Unit1’,‘Unit2’,‘Unit3’]
event = [‘Active’,‘Active’,‘Active’]
start = [‘2010-01-01 01:00:00’,‘2010-01-01 05:00:00’,‘2010-01-01 07:00:00’]
finish = [‘2010-01-01 15:00:00’,‘2010-01-01 16:00:00’,‘2010-01-01 17:00:00’]
df_active = pd.DataFrame({‘Unit’:unit,‘Start’:start,‘Finish’:finish,‘Event’:event})
df_base=df_active
print df_base
traces=[]
for i in range(len(df_base)):
trace0 = go.Bar(
y=[df_base['Unit'].loc[i],df_base['Unit'].loc[i]],
x=[df_base['Start'].loc[i],df_base['Finish'].loc[i]],
orientation = 'h',
marker=dict(
color='green'
),
name='task active',
hoverinfo = "text",
text = 'start'+' '+df_base['Start'].loc[i]
)
traces.append(trace0)
data = traces
layout=go.Layout(barmode=‘overlay’,xaxis=dict(type=‘date’))
app = dash.Dash()
app.layout = html.Div(
[
dcc.Graph(id=‘gantt’,figure={‘data’:data,‘layout’:layout})
]
)
if name == ‘main’:
app.run_server(debug=True)