【发布时间】:2017-08-11 03:04:42
【问题描述】:
Plotly 的甘特图示例(示例如下:https://plot.ly/python/gantt/、https://plot.ly/r/gantt/)仅在条形的端点上(或附近)显示悬停文本。
悬停在栏内时是否可以显示悬停文本?
我尝试添加:hoveron = "points+fills"(使用 R 版本)但没有帮助。
谢谢,欧文
【问题讨论】:
标签: plotly
Plotly 的甘特图示例(示例如下:https://plot.ly/python/gantt/、https://plot.ly/r/gantt/)仅在条形的端点上(或附近)显示悬停文本。
悬停在栏内时是否可以显示悬停文本?
我尝试添加:hoveron = "points+fills"(使用 R 版本)但没有帮助。
谢谢,欧文
【问题讨论】:
标签: plotly
尝试在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
【讨论】: