草庐IT

javascript - rCharts nvd3 lineWithFocusChart 自定义

coder 2023-07-04 原文

我在 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/

有关javascript - rCharts nvd3 lineWithFocusChart 自定义的更多相关文章

随机推荐