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
isotop
June 20, 2018, 7:53am
4
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
bcd
June 22, 2018, 7:08am
6
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)
aminbe
September 19, 2019, 4:14pm
7
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,
ebfa
September 28, 2019, 6:44am
8
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
aminbe
September 28, 2019, 9:01pm
9
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
ebfa
September 30, 2019, 6:08am
10
Alright I’ll try. Thanks.
vvv
March 31, 2020, 1:22pm
11
aminbe:
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”)
----> 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
aminbe
April 7, 2021, 3:46pm
12
Have you tried to print figure content ? You will then see the data structure inside …