hovertemplate not rendering text for single items in the plot
未关闭
还没有人认领这个 Issue。
- 主要语言
- R
- 星标
- 2.7k
- 派生
- 641
- PR 合并指标
- 30 天内没有已合并 PR
描述
When using hovertemplate in bar charts to annotate bars,
if the variable is present only once then text annotation doesn't work
For example in below image, Type B is only present once
and when hovered on it shows as "%{text}

but when using hoverinfo it seems to work fine

I need to use hovertemplate, as i had to use it in a function, where color and text options are passed as variable
any workaround to fix this?
Reproducible code example
library(data.table)
library(plotly)
data <- data.table(Date = c(rep(as.Date("2022-10-18"), 3),
rep(as.Date("2022-10-19"), 3),
rep(as.Date("2022-10-20"), 3)),
Type = c('A', 'B', 'C', 'A', 'D', 'C', 'C', 'D', 'A'),
Frequency = c(6, 3, 6, 10, 9, 9, 9, 3, 2))
# hovertemplate - Type B is only one entry and it shows as %{text}
plot_ly(data, x=~Date, y=~Frequency, color=~Type, type='bar', text=~Type,
hovertemplate=paste('<b>%{text}</b>',
'<br><b>%{y}</b>',
'<br><b>%{x}</b>',
'<extra></extra>')) %>%
layout(barmode="stack")
# hoverinfo - works as expected
plot_ly(data, x=~Date, y=~Frequency, color=~Type, type='bar',
hoverinfo = 'text',
text = ~paste('<b>', Type, '</b>',
'<br><b>', Date, '</b>',
'<br><b>', Frequency, '</b>')) %>%
layout(barmode="stack")
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
运行 issue 中可复现的 R 示例,并比较 hovertemplate 和 hoverinfo 的输出,重点关注唯一的 Type B 条形。跟踪 R 包使用的 Plotly 渲染路径;当 hovertemplate 显示 Type B 文本而不是字面量 %{text} 时完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- plotly, r
- 领域
- data-visualization
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 45/100