rCharts nvd3 lineWithFocusChart 自定义

50

我正在使用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

是的,我相信rCharts已经停滞不前了。我无法使用y2Axis,所以我认为它没有被纳入,而且我不认为它会被纳入,不幸的是。 - johnny838
嗨NicE,我暂时放弃了lineWithFocusChart,非常感谢你的帮助。最近我尝试从你的存储库安装rCharts,但是y2Axis奇怪地采用与xAxis相同的格式。令人惊讶的是,x2Axis采用y轴格式,但是将视图查找器的x轴格式化为y轴格式。这是有问题的,因为我最终希望较低的x轴具有与y轴不同的格式(日期格式)。如果您愿意查看,我可以提供一个单独的示例。谢谢! - johnny838
1个回答

2

我在查看标记为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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接