Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hovertemplate not rendering text for single items in the plot #2213

Open
shyamrallapalli opened this issue Dec 8, 2022 · 2 comments
Open

Comments

@shyamrallapalli
Copy link


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")
@shyamrallapalli
Copy link
Author

shyamrallapalli commented Dec 14, 2022

Now i got another question for hoverinfo
is there any way to hide default text showing on top of third bar - "D 2022-10-20 3", with out any cursor
Any pointers, please?
--> ok got this sorted by adding textposition='none'

would be great to hear if anyone has any insights on hovertemplate bug/issue

@ismirsehregal
Copy link

A similar issue came up here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants