甘特图的Plotly示例(示例在此处:https://plot.ly/python/gantt/,https://plot.ly/r/gantt/)仅显示悬停文本在终点的上方(或附近)酒吧。
悬停在栏内时是否可以显示悬停文字?
我尝试添加:hoveron = "points+fills"
(使用R版本),但这没有帮助。
谢谢,Erwin
答案 0 :(得分:1)
尝试在layout
中设置hovermode = "y"
,以便在鼠标光标位于条形图上时获取悬停切换弹出窗口。
来自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