hovertemplate not rendering text for single items in the plot
Nessuno ha ancora preso questa issue.
- Lingua principale
- R
- Stelle
- 2.7k
- Fork
- 641
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
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")
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Eseguire l’esempio R riproducibile dell’issue e confrontare gli output di hovertemplate e hoverinfo, concentrandosi sull’unica barra Type B. Tracciare il percorso di rendering di Plotly utilizzato dal pacchetto R; il lavoro è completato quando hovertemplate visualizza il testo Type B invece del valore letterale %{text}.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- plotly, r
- Ambito
- data-visualization
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 45/100