admin管理员组文章数量:1430151
I am working with nvd3 on rCharts and was wondering if there was a way to customize the axes for the lower view finder graph on a lineWithFocusChart. I have provided a reproducible example below, where I customize the x and y axes to have mas separating the thousands place, but that formatting does not show up on the lower view finder chart. How could this be solved? Thank you!
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 <- ".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
I am working with nvd3 on rCharts and was wondering if there was a way to customize the axes for the lower view finder graph on a lineWithFocusChart. I have provided a reproducible example below, where I customize the x and y axes to have mas separating the thousands place, but that formatting does not show up on the lower view finder chart. How could this be solved? Thank you!
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
Share
Improve this question
asked Jul 17, 2015 at 15:48
johnny838johnny838
9327 silver badges15 bronze badges
2
- Yeah I believe rCharts has stagnated. I could not use y2Axis, so I don't think it got incorporated in and I don't think it ever will be unfortunately. – johnny838 Commented Jul 21, 2015 at 15:17
- Hi NicE, I ended up dropping lineWithFocusChart for awhile, and I greatly appreciate you helping out. I recently tried installing the rCharts from your repository, but the y2Axis takes on the same format as the xAxis strangely. Surprisingly, x2Axis takes on the y axis formatting, but then formats the view finder's x axis with the y axis format as well. This is problematic because I eventually want the lower x axis to have a different format (a date format) from the y axis. I can provide a separate example if you're willing to take a look. Thanks! – johnny838 Commented Aug 4, 2015 at 13:51
1 Answer
Reset to default 2I just discovered this as I was looking at unanswered questions tagged R
. Sorry I missed it. rCharts
has stalled, but look for an new version based on the more flexible htmlwidgets
infrastructure. I am sure this answer is far too late, but I have changed the template to allow formatting for y2Axis
.
# unment 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
本文标签: javascriptrCharts nvd3 lineWithFocusChart CustomizationStack Overflow
版权声明:本文标题:javascript - rCharts nvd3 lineWithFocusChart Customization - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745463644a2659435.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论