例如,在这样的 dygraph 上:
library(dygraphs)
lungDeaths <- cbind(mdeaths, fdeaths)
dygraph(lungDeaths)
我想自定义标签如下。代替
1974 年 1 月 1974 年
2 月
等
我想看看:
1974 年 1 月 (1)
1974 年 2 月 (2)
等。
我不在乎计数器是否在日期上连接,我只想查看期间增量数字,因为鼠标在系列上移动。(当然没有在图表上显示为系列)
例如,在这样的 dygraph 上:
library(dygraphs)
lungDeaths <- cbind(mdeaths, fdeaths)
dygraph(lungDeaths)
我想自定义标签如下。代替
1974 年 1 月 1974 年
2 月
等
我想看看:
1974 年 1 月 (1)
1974 年 2 月 (2)
等。
我不在乎计数器是否在日期上连接,我只想查看期间增量数字,因为鼠标在系列上移动。(当然没有在图表上显示为系列)
您可以创建一个自定义的valueFormatter
,并使用row
参数来捕获周期数。这是一个例子:
library(dygraphs)
library(htmlwidgets)
lungDeaths <- cbind(mdeaths, fdeaths)
date_counter <- 'function(d,opts, seriesName, dygraph, row, col){
var monthNames = ["Jan", "Feb", "Mar", "Apr", "May", "Jun","Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
date = new Date(d);
return monthNames[date.getMonth()]+", " +date.getFullYear() + " (" + row.toString() + ")";
}'
dygraph(lungDeaths) %>%
dyAxis("x",valueFormatter=JS(date_counter))