Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the legend's timestamp format in R dygraphs

Tags:

r

dygraphs

I'm charting a time series with dygraphs in R like the following:

library(dygraphs)
library(htmlwidgets)
library(data.table)

now <- Sys.time()
dataset <- data.table(time = as.POSIXct(now+1:10),value = 1:10)
d <- dygraph(dataset) 

The date format displayed in the legend depends in the machine locale and I cannot leave it fixed.

The labels of the x axis can be formatted as follows:

valueFormatter<-"function formatValue (ms) {
                return ms.toISOString();
}"

d <- d%>%dyAxis("x", axisLabelFormatter=JS(valueFormatter))

However, I don't know how to do it for the legend.

like image 748
Jon Nagra Avatar asked Mar 06 '18 10:03

Jon Nagra


1 Answers

Similar to axisLabelFormatter there is legendForamtter. See for examples:

https://github.com/danvk/dygraphs/pull/683 http://dygraphs.com/tests/legend-formatter.html

like image 177
Amar Avatar answered Sep 24 '22 16:09

Amar