I am plotting Gannt chart using plotly express timeline function. I am having problems with the hover text rendering of the date field.
plotly version: 4.5.4
The original example given here https://plotly.com/python/gantt/, the Finish field renders in the right format as %Y-%m-%d .
import plotly.express as px
import pandas as pd
df = pd.DataFrame([
dict(Task="Job A", Start='2009-01-01', Finish='2009-02-28', Resource="Alex")
])
fig = px.timeline(df, x_start="Start", x_end="Finish", y="Task", color="Resource")
fig.update_yaxes(autorange="reversed")
fig.show()
I tried customizing the hover text fields using the below code.
import plotly.express as px
import pandas as pd
df = pd.DataFrame([
dict(Task="Job A", Start='2009-01-01', Finish='2009-02-28', Resource="Alex")
])
fig = px.timeline(df, x_start="Start", x_end="Finish", y="Task", color="Resource"
, hover_data={"Start": True,
"Finish": True,
"Task": True,
"Resource": False}
)
fig.show()
Now, the Finish field shown is the difference of Start and Finish in milliseconds. In the above example the 'Finish' value is shown as 5011200000.
I need the original Finish value to be shown in the hover text. In this case 2009-02-28.
I could only solve this by creating a copy of Finish column in my dataframe and use that for the hover text.
Is there a way I get the correct rendering of the column without duplicating it?
