Closed malexan closed 8 years ago
OK, there is a axisLabelFormatter
option in dyAxis()
function:
JavaScript function to call to format the tick values that appear along an axis (see the dygraphs documentation for additional details).
And based on SOF answer the function should look like this:
function(date, granularity, opts, dygraph) {
var months = ['leden', 'únor', 'březen', 'duben', 'květen',
'červen', 'červenec', 'srpen', 'září',
'říjen', 'listopad', 'prosinec'];
return months[date.getMonth()] + " " + date.getFullYear()
}
So should I pass it just like a character string?
Don't need to pass a function as shown in link above.
Here is a working example:
dygraph( samp.xts ) %>%
dyAxis(name="x",
valueFormatter="function(d){ var date = new Date(d); return (date.getSeconds()/10) }",
axisLabelFormatter="function(d){ return (d.getSeconds()/10) }"
)
So working example:
## Setting system locale to extract names of months from OS
## ru_RU.itf8 as in LInux. Probably UTF-8 in Windows
Sys.setlocale("LC_TIME","ru_RU.utf8")
## Extraction of months' names
months <- format(ISOdate(2004,1:12,1),"%B")
## Converting names to a string for JS-function
months <- paste0("'",
paste0(months, collapse = "', '"),
"'")
## Forming JS-function
axlabform <- paste0(
"function(date, granularity, opts, dygraph) {
var months = [",
months,
"]; return months[date.getMonth()] + \" \" + date.getFullYear()}")
library(dygraphs)
lungDeaths <- cbind(mdeaths, fdeaths)
dygraph(lungDeaths) %>%
dyAxis("x", axisLabelFormatter = axlabform)
http://stackoverflow.com/q/20332764/3190110
Need to use axisLabelFormatter JS-function. The question is how to use this function from R.