Erwin Kalvelagen
Erwin Kalvelagen

Reputation: 16742

Plotly Gantt Chart, hover inside bar

The Gantt charts example of Plotly (examples are here: https://plot.ly/python/gantt/, https://plot.ly/r/gantt/) only show the hover text when on (or near) the end-points of the bars.

Is it possible to show the hover text when hovering inside the bars?

I tried to add: hoveron = "points+fills" (using the R version) but that did not help.

Thanks, Erwin

Upvotes: 0

Views: 2570

Answers (1)

Maximilian Peters
Maximilian Peters

Reputation: 31689

Try setting hovermode = "y" in layout to get the hoverover popup when the mouse cursor is on the bar.

Modified example from here.

library(plotly)
df <- read.csv("https://cdn.rawgit.com/plotly/datasets/master/GanttChart-updated.csv", stringsAsFactors = F)
df$Start <- as.Date(df$Start, format = "%m/%d/%Y")
client = "Sample Client"
p <- plot_ly() %>% layout(hovermode = "y")

for(i in 1:(nrow(df) - 1)){
  p <- add_trace(p,
                 x = c(df$Start[i], df$Start[i] + df$Duration[i]),
                 y = c(i, i),
                 type = "scatter",
                 mode = "lines",
                 line = list(width = 20),
                 showlegend = F,
                 hoverinfo = "text",
                 text = paste("Task: ", df$Task[i], "<br>",
                              "Duration: ", df$Duration[i], "days<br>",
                              "Resource: ", df$Resource[i])
  )
} 

p

enter image description here

Upvotes: 3

Related Questions