[英]rCharts tooltip content for multiplie lines
我是一個簡單的R編碼器,幾乎沒有使用javascript HTML進行編碼的經驗,因此我很難理解工具提示自定義代碼的包裝。
我有兩個用rCharts lineWithFocusChart繪制的時間序列,現在我想自定義工具提示,如下所示: http ://shiny.rstudio.com/gallery/nvd3-line-chart-output.html
到目前為止,這是我的代碼:
shinyServer(function(input, output) {
output$myChart <- renderChart({
select<-as.numeric(input$radioTS)
out <- data.frame(Actuals[,select], Fits[,select], mmmyyyy)
colnames(out) <- c("Actuals","Fits","Date")
data<-melt(out,id.vars = 'Date')
data$Date <- as.numeric(as.POSIXct(data$Date)) * 1000
p1 <- nPlot(
value ~ Date,
group = 'variable',
data = data,
type = 'lineWithFocusChart',
width = 650,
height = 500
)
p1$addParams(dom = 'myChart')
p1$xAxis(tickFormat = "#!function(d) {return d3.time.format('%b %Y')(new Date(d))}!#")
p1$x2Axis(tickFormat = "#!function(d) {return d3.time.format('%Y')(new Date(d))}!#")
p1$yAxis(tickFormat = "#!function(d) {return d3.format('0,.0')(d)}!#")
return(p1)
})
})
引用的閃亮示例使用nvd3 interactiveGuideline
功能。 要在rCharts中使用此功能,可以使用p1$chart(useInteractiveGuideline=TRUE)
,但是由於此nvd3問題 , lineWithFocusChart
尚不提供此功能,因此現在我們僅限於lineChart
。
不幸的是,nvd3當前不支持InteractiveGuideline的自定義,因為此請求請求尚未被接受。 但是,如本例所示,通過適當的命名,您可以獲得相當不錯的工具提示。
shinyServer(function(input, output) {
output$myChart <- renderChart({
select<-as.numeric(input$radioTS)
out <- data.frame(Actuals[,select], Fits[,select], mmmyyyy)
colnames(out) <- c("Actuals","Fits","Date")
data<-melt(out,id.vars = 'Date')
data$Date <- as.numeric(as.POSIXct(data$Date)) * 1000
p1 <- nPlot(
value ~ Date,
group = 'variable',
data = data,
type = 'lineChart', # see explanation for why not lineWithFocusChart
width = 650,
height = 500
)
p1$addParams(dom = 'myChart')
p1$xAxis(tickFormat = "#!function(d) {return d3.time.format('%b %Y')(new Date(d))}!#")
#commented x2Axis out since only lineChart
#p1$x2Axis(tickFormat = "#!function(d) {return d3.time.format('%Y')(new Date(d))}!#")
p1$yAxis(tickFormat = "#!function(d) {return d3.format('0,.0')(d)}!#")
p1$chart(useInteractiveGuideline = TRUE)
return(p1)
})
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.