How to set the local month names in echarts4r calendar

657 views Asked by At

Is there a way to set the language of the dates in the echarts4r calendar to the local time?

This is how to get the Icelandic abbreviated month names but in the echarts4r calendar it's still in English.

Sys.setlocale("LC_TIME", "Icelandic")
format(Sys.time(), '%d %b %Y')

I also tried Sys.setenv(LANGUAGE = "is")

This is the example calendar that I'm working with:

dates <- seq.Date(as.Date("2017-01-01"), as.Date("2018-12-31"), by = "day")
values <- rnorm(length(dates), 20, 6)
year <- data.frame(date = dates, values = values)
year %>% 
  e_charts(date) %>% 
  e_calendar(range = "2018") %>% 
  e_heatmap(values, coord_system = "calendar") %>% 
  e_visual_map(max = 30) %>% 
  e_title("Calendar", "Heatmap")
1

There are 1 answers

0
Guillaume On BEST ANSWER

In fact there is an option for this in echarts :

https://echarts.apache.org/en/option.html#calendar.monthLabel.nameMap

You can specify language in nameMap for day and month labels.

I have tried in R for french with following option in monthLabel list of parameters : nameMap = 'fr' but it doesn't seems to work.

Here is a solution that worked for me in french using lubridate fonction month. (and almost the same for day labels where I put monday as the first day and manually set french day abbreviation for short).

I have added a formatter to print day and value on hover in e_tooltip.

library(lubridate)
library(dplyr, warn.conflicts = FALSE)
library(echarts4r)

temp_data %>% 
  mutate(value_to_plot = ifelse(value_to_plot == 0, NA, value_to_plot)) %>% 
  e_charts(DATE_J) %>% 
  e_calendar(range = "2020",
             top="60", 
             left = 150, 
             dayLabel = list(
                        firstDay=1, 
                        nameMap = c('Di', 'Lu', 'Ma', 'Me', 'Je', 'Ve', 'Sa')),
             monthLabel = list(
                          nameMap = month(1:12, label = TRUE, abbr = FALSE))) %>%
  e_heatmap(value_to_plot, coord_system = "calendar") %>% 
   e_visual_map(min = 1L, max = max(temp_data$value_to_plot), top = 130, left = 15) %>% 
  e_tooltip(formatter = htmlwidgets::JS("
                                    function(params){
                                    return(params.value[0] + ': ' + params.value[1])
                                    }
                                    ")) %>% 
            e_title("Title", "Subtitle")

echarts with french date labels

Guillaume