Closed
Description
The gantt chart legend sometimes scrolls unnecessarily.
Cross references:
- Community forums thread: https://community.plot.ly/t/gantt-chart-set-legend-colorbar-at-the-top-of-chart/14733/19.
- PR that addressed legend entries being pushed to the bottom: Show colors at the top of the gantt's colorbar #1110
import pandas as pd
from plotly.offline import init_notebook_mode, iplot
import plotly.figure_factory as ff
init_notebook_mode()
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
iplot(gantt_fig3(df1))