Hover style of label in googleVis

不打扰是莪最后的温柔 提交于 2019-12-13 00:48:13

问题


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


来源:https://stackoverflow.com/questions/36125419/hover-style-of-label-in-googlevis

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!