Grouped Gantt chart

Hey guys,

I am trying to create a Gantt chart using Plotly, the goal of which is to display the activity of a group of servers over a day. For example, a server might be running or stopped, and I would like to display its status over a 24 hour period.

The Gantt chart appears to accomplish this, using a combination of the ‘Using Hours and Minutes in Times’ and ‘Group Tasks Together’ examples provided here:

However I am having issues getting this to work. I think the problem may be with how my data appears when uploaded to Plotly, in the example from the tutorial the data appears as below:


Whereas my data appears like this:

My code is basically a carbon copy of the ‘Using Hours and Minutes’ example, with the addition of grouptasks=True. My data exists in a Pandas Dataframe that is handed to Plotly as such:

graphData = weeklyDetailed_Servers[[‘Name’, ‘Start Time’, ‘End Time’, ‘Status’]]
graphData = graphData.rename(index=str, columns={‘Name’: ‘Task’, ‘Start Time’: ‘Start’, ‘End Time’: ‘Finish’,
‘Status’: ‘Resource’})

colors = dict(Running=‘rgb(46, 137, 205)’,
Stopped=‘rgb(114, 44, 121)’)

fig = ff.create_gantt(df, colors=colors, index_col=‘Resource’, title=‘Daily Schedule’,
show_colorbar=True, bar_width=0.8, showgrid_x=True, showgrid_y=True, group_tasks=True)
py.plot(fig, filename=‘gantt-hours-minutes’, world_readable=True)

Any help or suggestions on fixing this would be greatly appreciated. I am open to using a different graph format as well if there are any better options!

Thanks in advance.

Hi @Kelsicle,

When I take the “Using Hours and Minutes in Times” example and add group_tasks it seems to work properly.

import plotly.graph_objs as go
import plotly.figure_factory as ff

df = [
    dict(Task='Morning Sleep', Start='2016-01-01', Finish='2016-01-01 6:00:00', Resource='Sleep'),
    dict(Task='Breakfast', Start='2016-01-01 7:00:00', Finish='2016-01-01 7:30:00', Resource='Food'),
    dict(Task='Work', Start='2016-01-01 9:00:00', Finish='2016-01-01 11:25:00', Resource='Brain'),
    dict(Task='Break', Start='2016-01-01 11:30:00', Finish='2016-01-01 12:00:00', Resource='Rest'),
    dict(Task='Lunch', Start='2016-01-01 12:00:00', Finish='2016-01-01 13:00:00', Resource='Food'),
    dict(Task='Work', Start='2016-01-01 13:00:00', Finish='2016-01-01 17:00:00', Resource='Brain'),
    dict(Task='Exercise', Start='2016-01-01 17:30:00', Finish='2016-01-01 18:30:00', Resource='Cardio'), 
    dict(Task='Post Workout Rest', Start='2016-01-01 18:30:00', Finish='2016-01-01 19:00:00', Resource='Rest'),
    dict(Task='Dinner', Start='2016-01-01 19:00:00', Finish='2016-01-01 20:00:00', Resource='Food'),
    dict(Task='Evening Sleep', Start='2016-01-01 21:00:00', Finish='2016-01-01 23:59:00', Resource='Sleep')

colors = dict(Cardio = 'rgb(46, 137, 205)',
              Food = 'rgb(114, 44, 121)',
              Sleep = 'rgb(198, 47, 105)',
              Brain = 'rgb(58, 149, 136)',
              Rest = 'rgb(107, 127, 135)')

fig = ff.create_gantt(df, colors=colors, index_col='Resource', title='Daily Schedule',
                      show_colorbar=True, bar_width=0.8, showgrid_x=True, showgrid_y=True, group_tasks=True)

Could you make a small example that I can copy/paste and see the problem you’re hitting (including some simple data)?

Also, when you post Python code, please put it inside a “fenced code block” ( This keep the markdown renderer from messing up the formatting :slightly_smiling_face: