Home > database >  How can I limit my dygraph X axis to last 48 hours?
How can I limit my dygraph X axis to last 48 hours?

Time:07-12

I have a dygraph from a data source with datetime. The graph shows the full 12 days of data, however I'd like the X axis to only show the last 48 hours. I'm trying this:

library(lubridate)
...
dyAxis('x', valueRange = c(now()-days(2), now())

But I still get the full 12 days displayed on load.

Any ideas how to do this?

CodePudding user response:

You could use dyRangeSelector with dateWindow parameter:

# Generate data
library(data.table)
data = data.table(x=as.Date("2000-01-01") 0:10,y=0:10)

# Draw graph
library(dygraphs)

enddate = max(data$x)
startdate = enddate - 2
dygraph(data) %>% dyRangeSelector(dateWindow = c(startdate,enddate))

enter image description here

valueRange only applies to y-axis.

  • Related