首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >rCharts nvd3 lineWithFocusChart自定义

rCharts nvd3 lineWithFocusChart自定义
EN

Stack Overflow用户
提问于 2015-07-17 23:48:58
回答 1查看 856关注 0票数 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
EN

回答 1

Stack Overflow用户

发布于 2015-08-28 02:04:31

我是在查看标记为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
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31479745

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档