Label a Gantt Chart

Hello,

How do I add text to be overlaid above each entry. With this:

		for i in range(len(fig["data"])):
			fig["data"][i].update(text=df[i]["Resource"], mode="text")

I get this:

I would like to have the labels be visible in the center of each region.

Thanks!
Benjamin

Still haven’t figured this one out. I’d appreciate any help I can get!

Bumping… still not sure how to do this

I have the same problem, any help would be appreciated

I gave up on plotly — ended up using the Google Charts timeline instead. It worked out of the box

Hey @benjamin and @isotop

Couldn’t you use something like annotations?

import plotly.plotly as py
import plotly.figure_factory as ff

df = [dict(Task="Job A", Start='2009-01-01', Finish='2009-02-28'),
      dict(Task="Job B", Start='2009-03-05', Finish='2009-04-15'),
      dict(Task="Job C", Start='2009-02-20', Finish='2009-05-30')]

fig = ff.create_gantt(df)

fig['layout']['annotations'] = [dict(x='2009-02-01',y=0,text="This is a label", showarrow=False, font=dict(color='white'))]

py.iplot(fig, world_readable=True)

Hello,

Yes I was able to use annotations in order to plot labels on gantt chart :
Here is the used function (you can change it if needed):

def addAnnot(df, fig):
    for i in df:
        x_pos = (i['Finish'] - i['Start'])/2 + i['Start']
        for j in fig['data']:
            if(j['name'] == i['Label]):
                y_pos = (j['y'][0] + j['y'][1] + j['y'][2] + j['y'][3])/4
        fig['layout']['annotations'] += tuple([dict(x=x_pos,y=y_pos,text=i['Label'],font={'color':'black'})])
    plotly.offline.plot(fig, filename="ganttChart.html")

I Hope this would be of some help

Br,

Hello,

Would it be possible for you to explain abit of what you did there?

I’m pretty new to python in general, but I think this is what I need.

BR

If you print the gantt chart you will see that it is composed of multiple scatter graphs (boxes filled with different colors), so the idea is to check the different scatters and identify there names and then add them as annotations … the best advice I can give you is to print the gantt chart print(fig) and then try to understand the function I have written

Alright I’ll try. Thanks.

----> 6 x_pos = (i[‘Finish’] - i[‘Start’]) / 2 + i[‘Start’]
TypeError: string indices must be integers

I’m surprised that Gantt chart don’t have basic option like label (without this hack) or change the color range and color scale

Have you tried to print figure content ? You will then see the data structure inside …