plotly / plotly/plotly.R

hovertemplate not rendering text for single items in the plot

Offen
#2,213 3 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
R
Sterne
2.7k
Forks
641
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung


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

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Führen Sie das reproduzierbare R-Beispiel aus dem Issue aus und vergleichen Sie die Ausgaben von hovertemplate und hoverinfo, wobei der Fokus auf dem einzelnen Type B-Balken liegt. Verfolgen Sie den vom R-Paket verwendeten Plotly-Renderingpfad; abgeschlossen, wenn hovertemplate den Type B-Text anstelle des Literals %{text} anzeigt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
plotly, r
Bereich
data-visualization
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
45/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.