Gantt Chart, set legend/colorbar at the top of chart

Hi @jmmease, I have the same issue as the other users, so I created a sample data that you can test.

import dash
import dash_core_components as dcc
import dash_html_components as html
import plotly.figure_factory as ff
import pandas as pd



df1 = pd.DataFrame({'TaskName': ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'I', 'J', 'K'],
                'StartDate1' : ['2019-03-27 00:00:00','2019-03-27 00:00:30', '2019-03-27 00:01:00', '2019-03-27 00:01:30', '2019-03-27 00:01:40',
                             '2019-03-27 00:02:30', '2019-03-27 00:03:00', '2019-03-27 00:03:30', '2019-03-27 00:04:00', '2019-03-27 00:04:30'],
                'EndDate1': ['2019-03-27 00:03:00', '2019-03-27 00:03:20', '2019-03-27 00:04:10', '2019-03-27 00:03:40', '2019-03-27 00:05:50',
                            '2019-03-27 00:06:40', '2019-03-27 00:07:10', '2019-03-27 00:08:00', '2019-03-27 00:08:20', '2019-03-27 00:08:40'],
                'StartDate2' : ['2019-03-27 00:03:00', '2019-03-27 00:03:20', '2019-03-27 00:04:10', '2019-03-27 00:03:40', '2019-03-27 00:05:50',
                            '2019-03-27 00:06:40', '2019-03-27 00:07:10', '2019-03-27 00:08:00', '2019-03-27 00:08:20', '2019-03-27 00:08:40'],
                'EndDate2': ['2019-03-27 00:04:00', '2019-03-27 00:04:20', '2019-03-27 00:05:10', '2019-03-27 00:05:40', '2019-03-27 00:06:50',
                            '2019-03-27 00:07:40', '2019-03-27 00:08:10', '2019-03-27 00:09:00', '2019-03-27 00:09:20', '2019-03-27 00:09:40']})

def gantt_fig3(df1):
    data3 = []
    for row in df1.itertuples():
        data3.append(dict(Task=str(row.TaskName), Start=str(row.StartDate1),
                      Finish=str(row.EndDate1), Resource='Resource1'))
        data3.append(dict(Task=str(row.TaskName), Start=str(row.StartDate2),
                      Finish=str(row.EndDate2), Resource='Resource2'))


    fig = ff.create_gantt(data3, index_col='Resource', title='Gantt Chart', show_colorbar = True, group_tasks = True , height=500, width=1300 )
    fig['layout'].update(legend=dict(traceorder='reversed'))
    return fig

app = dash.Dash()


app.layout = html.Div(children=[
    html.H1(children='Gantt Chart'),       
    dcc.Graph(
        id='gantt-chart',
        figure = gantt_fig3(df1))
])

if __name__ == '__main__':
    app.run_server(debug=True, port=9000)

This is the output that I get. The command ‘traceorder=reversed’ places the legend at the top. Also, because I said that ‘group_tasks=True’, the tasks are displayed from the top to the bottom, and not from bottom to top.
My version of plotly is 3.4.1

1 Like