【问题标题】:Hover style of label in googleVisgoogleVis中标签的悬停样式
【发布时间】:2016-03-21 07:39:02
【问题描述】:

我正在尝试更改 googleVis columnChart 中悬停标签的样式。我想格式化大数字,因为它是在轴上完成的。你知道如何管理它(我已经阅读了整个互联网,但仍然不知道如何修复它:D)?

我的问题的说明(红色是我拥有的格式,绿色是我想要的格式):

还有闪亮的应用示例:

ui.R:

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

shinyUI(fluidPage(

    htmlOutput("wyk")

))

和服务器.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))

    })

})

【问题讨论】:

  • 本质上你想用空格隔开每三个数字吗?
  • @RomanLuštrik,是的,没错。
  • 这可能更像是一个 javascript 问题。让我们看看是否有熟悉 googlevis API 的人可以了解如何为标签设置数字格式,就像在 gvisTable 中设置文本格式一样。跨度>
  • 是的 - 我知道这一点。问题是我根本不懂javascript...

标签: javascript r shiny googlevis


【解决方案1】:

您可以使用要显示的文本创建一个额外的列变量,并传递一个 y 变量向量,给标签 aame 以“.tooltip”结尾。工具提示可以使用 html 标签进行样式设置。 formatbig.mark 可以在 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))
  })
})

【讨论】:

  • 谢谢!它不像自动的那么漂亮,但它可能可以使用 html 进行更改。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-03-28
  • 2016-06-07
  • 2012-01-19
  • 1970-01-01
  • 2011-02-09
  • 2012-10-11
  • 1970-01-01
相关资源
最近更新 更多