gpt4 book ai didi

javascript - rCharts nvd3 lineWithFocusChart 自定义

转载 作者:IT王子 更新时间:2023-10-29 03:00:33 25 4
gpt4 key购买 nike

我在 rCharts 上使用 nvd3,想知道是否有办法在 lineWithFocusChart 上自定义下部取景器图表的轴。我在下面提供了一个可重现的示例,我在其中自定义 x 轴和 y 轴以用逗号分隔千位,但该格式不会显示在下方的取景器图表上。这怎么能解决?谢谢!

      library(rCharts)
temp <- data.frame(x = 1:2000, y = 1:2000, z = c(rep(1,1000), rep(0,1000)))
g <- nPlot(y ~ x, group = "z", data = temp, type = "lineWithFocusChart")
g$templates$script <- "http://timelyportfolio.github.io/rCharts_nvd3_templates/chartWithTitle_styled.html"
g$set(title = "Example")
g$chart(transitionDuration = -1,
tooltipContent = "#! function(key, x, y) {
return 'z: ' + key + '<br/>' + 'x: ' + x + '<br/>' + 'y: ' + y
}!#",
showLegend = FALSE, margin = list(left = 200,
right = 100,
bottom = 100,
top = 100))
g$xAxis(axisLabel = "x",
tickFormat = "#!function(x) {return d3.format(',.0f')(x);}!#")
g$yAxis(axisLabel = "y",
width = 100,
tickFormat = "#!function(y) {return d3.format(',.0f')(y);}!#",
showMaxMin = FALSE)
g

最佳答案

我刚刚在查看标记为 R 的未回答问题时发现了这一点。对不起,我错过了。 rCharts 已停滞,但正在寻找基于更灵活的 htmlwidgets 基础架构的新版本。我确信这个答案已经太晚了,但我已经更改了模板以允许对 y2Axis 进行格式化。

# uncomment this to install the fix
#devtools::install_github("timelyportfolio/rCharts")

library(rCharts)
temp <- data.frame(x = 1:2000, y = 1:2000, z = c(rep(1,1000), rep(0,1000)))
g <- nPlot(y ~ x, group = "z", data = temp, type = "lineWithFocusChart")
g$templates$script <- "c:/users/kent.tleavell_nt/dropbox/development/r/rCharts_nvd3_templates/chartWithTitle_styled.html"
g$set(title = "Example")
g$chart(transitionDuration = -1,
tooltipContent = "#! function(key, x, y) {
return 'z: ' + key + '<br/>' + 'x: ' + x + '<br/>' + 'y: ' + y
}!#",
showLegend = FALSE, margin = list(left = 200,
right = 100,
bottom = 100,
top = 100))
g$xAxis(axisLabel = "x",
tickFormat = "#!function(x) {return d3.format(',.0f')(x);}!#")
g$yAxis(axisLabel = "y",
width = 100,
tickFormat = "#!function(y) {return d3.format(',.0f')(y);}!#",
showMaxMin = FALSE)
g$x2Axis(tickFormat = "#!function(x) {return d3.format('1.2s')(x);}!#")

# now we have a new y2Axis function
g$y2Axis(
tickFormat = "#!function(y) {return d3.format('1.2s')(y);}!#"
)

g

关于javascript - rCharts nvd3 lineWithFocusChart 自定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31479745/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com