But the resulting plot rounds the fractional x values to whole seconds. I found the following two links to show how to handle milliseconds.
I read carefully both posts and tried to create my own version below. I can not get it to work. My browser shows a blank page, and the java console shows the message "Uncaught TypeError: d.getHours is not a function".
Please help me get this to a working example. Thanks.
library(dygraphs)
CustomAxisLabel <- 'function (d, gran) {
return Dygraph.zeropad(d.getHours()) + ":" +
Dygraph.zeropad(d.getMinutes()) + ":" +
Dygraph.zeropad(d.getSeconds()) + "." +
Dygraph.zeropad(d.getMilliseconds());
}'
CustomValueFormat = 'function (ms) {
var d = new Date(ms);
return Dygraph.zeropad(d.getHours()) + ":" +
Dygraph.zeropad(d.getMinutes()) + ":" +
Dygraph.zeropad(d.getSeconds()) + "." +
Dygraph.zeropad(d.getMilliseconds());
}'
len <- 60 * 60 + 10
RDData <- xts(runif(len,0,1), seq(as.POSIXct("2015-04-01 10:00:00"), as.POSIXct("2015-04-02 15:00:00"), length = len),tz="GMT")
dygraph(RDData) %>% dyOptions(useDataTimezone = TRUE) %>% dyAxis("x",axisLabelFormatter =JS(CustomAxisLabel),valueFormatter=JS(CustomValueFormat))