plotly / plotly/plotly.R

hovertemplate not rendering text for single items in the plot

Ouverte
#2,213 3 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Langage dominant
R
Étoiles
2.7k
Forks
641
Métriques de merge des PR
Aucune PR mergée en 30 j

Description


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}
hovertemplate

but when using hoverinfo it seems to work fine
hoverinfo

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")

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Exécutez l’exemple R reproductible de l’issue et comparez les sorties de hovertemplate et hoverinfo, en vous concentrant sur l’unique barre Type B. Suivez le chemin de rendu de Plotly utilisé par le package R ; c’est terminé lorsque hovertemplate affiche le texte Type B au lieu du littéral %{text}.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
plotly, r
Domaine
data-visualization
Type d'issue
Bug
Difficulté
3/5
Temps estimé
1-2 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
45/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.