Hover style of label in googleVis

2019-07-28 20:59发布

问题:

I'm trying to change the style of hover-label in googleVis columnChart. I'd like to format large numbers as it is done on axis. Do you know how to manage it (I've read whole Internet and still don't know how to fix it :D)?

The illustration of my problem (red is the format I have and green that I'd like to have):

And shiny-app example:

ui.R:

library("shiny")
library("googleVis")

shinyUI(fluidPage(

    htmlOutput("wyk")

))

and server.R:

library("shiny")
library("googleVis")
library("dplyr")

shinyServer(function(input, output) {

    d <- iris %>% group_by(Species) %>% summarise(ile=1e6*sum(Sepal.Length))

    output$wyk <- renderGvis({

      gvisBarChart(d, xvar = "Species", yvar = "ile",
                      options=list(legend="top", bar="{groupWidth:'90%'}", height=500))

    })

})

回答1:

You can create an extra column variable with the text you want to display and pass a vector of y-variables, giving the label aame ending in ".tooltip". The tooltip can be styled with html tags. format with big.mark can add commas in R.

shinyServer(function(input, output) {

    d <- iris %>% group_by(Species) %>% summarise(ile=1e6*sum(Sepal.Length))
  d$ile.tooltip <- sprintf("<p><b>%s</b><br/><b>%s</b></p>", 
    d$Species, format(d$ile, big.mark=","))

  output$wyk <- renderGvis({
    gvisBarChart(d, xvar = "Species", yvar = c("ile", "ile.tooltip"),
      options=list(legend="top", 
        tooltip="{isHtml:'True'}",  # so you can format it with html
        bar="{groupWidth:'90%'}", height=500))
  })
})