我正在尝试在googleVis columnChart中更改悬停标签的样式。我想格式化大数字,因为它是在轴上完成的。您知道如何管理它(我已经阅读了整个Internet,但仍然不知道如何解决它:D)?
我的问题的图示(红色是我想要的格式,绿色是我想要的格式):
和闪亮的应用程序示例:
ui.R:
library("shiny")
library("googleVis")
shinyUI(fluidPage(
htmlOutput("wyk")
))
和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))
})
})
最佳答案
您可以使用要显示的文本创建一个额外的列变量,并传递一个y变量向量,为标签提供一个以“ .tooltip”结尾的名称。工具提示可以使用html标记设置样式。 format
和big.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))
})
})
关于javascript - googleVis中标签的悬停样式,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36125419/