简体   繁体   English

shiny Dygraphs 上的本地化日期

[英]Localizing date on shiny Dygraphs

I've searched a little bit and found this answer: https://stackoverflow.com/a/32174139/152016我搜索了一下,找到了这个答案: https://stackoverflow.com/a/32174139/152016

But I don't know how to apply these settings on a shiny dygraph.但我不知道如何在 shiny dygraph 上应用这些设置。

I would really like to see localized date formats both on x axis and in the graph label.我真的很想在 x 轴和图表 label 上看到本地化的日期格式。

Just for curiosity data (it really doesn't matter), here's specific code:只是为了好奇数据(真的没关系),这里是具体的代码:

xtsdata <- tbl_xts(dados %>% filter(localidade%in%dados$localidade), cols_to_xts = "totalCases", spread_by = "localidade")

dygraph(xtsdata, xlab='Dia', ylab='Casos (acumulado)', main="Gráfico temporal") %>%
      dyRangeSelector() %>%
      dyHighlight(highlightCircleSize = 3, 
      highlightSeriesBackgroundAlpha = 0.8,
      highlightSeriesOpts = list(strokeWidth = 2)) %>%
      dyOptions(colors = RColorBrewer::brewer.pal(9, "Set2")) %>%
      dyLegend(show = "follow")

It was simpler than expected, the only mislead was that both properties belong to x axis formatting.它比预期的要简单,唯一的误导是这两个属性都属于 x 轴格式。

Just add:只需添加:

dyAxis("x", axisLabelFormatter = 'function(d) { return moment(d).format("DD/MMM");}', valueFormatter = 'function(ms) { return moment(ms).format("DD[ de ]MMMM[ de ]YYYY"); }')

(For localization I've decided to use moment.js ) (对于本地化,我决定使用moment.js

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM