hovertemplate not rendering text for single items in the plot
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- R
- Star
- 2.7k
- Fork
- 641
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
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")
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Chạy ví dụ R có thể tái lập từ issue và so sánh các đầu ra của hovertemplate và hoverinfo, tập trung vào thanh Type B duy nhất. Truy vết đường dẫn kết xuất Plotly được gói R sử dụng; hoàn tất khi hovertemplate hiển thị văn bản Type B thay vì chuỗi literal %{text}.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- plotly, r
- Lĩnh vực
- data-visualization
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 45/100