echarts4r
echarts4r copied to clipboard
Problem with e_formatter for e_heatmap
When I use e_tooltip normally it appears to work. For example this code:
tibble( Year=c(1,1,1,2,2,2,3,3,3), Category=c("A","B","C","A","B","C","A","B","C"), money = c(100,200,100,200,300,200,400,150,600) ) %>% e_chart(Category) %>% e_heatmap(Year,money) %>% e_visual_map(money,show=FALSE) %>% e_tooltip(trigger = "item")
Which doesn't use a formatter, correctly returns a tooltip with the right values (i.e. the Category and money value)
If you actually try to format as currency
tibble( Year=c(1,1,1,2,2,2,3,3,3), Category=c("A","B","C","A","B","C","A","B","C"), money = c(100,200,100,200,300,200,400,150,600) ) %>% e_chart(Category) %>% e_heatmap(Year,money) %>% e_visual_map(money,show=FALSE) %>% e_tooltip(trigger = "item",formatter = e_tooltip_item_formatter("currency"))
The tooltip (needs to be shown in browser) gets messed up and shows the Year as the value and adds in "series0" as the category.
Any help would be great!
I would add that there is a workaround using a javascript function to manually convert to currency - but it was the specific implementation of e_tooltip_item_formatter that this issue was meant to flag!
i.e. this works as a workaround
tibble( Year=c(1,1,1,2,2,2,3,3,3), Category=c("A","B","C","A","B","C","A","B","C"), money = c(100,200,100,200,300,200,400,150,600) ) %>% e_chart(Category) %>% e_heatmap(Year,money) %>% e_visual_map(money,show=FALSE) %>% e_tooltip(trigger = "item", formatter = htmlwidgets::JS("function(params){ var formatter = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD', }); return(params.value[0] +' '+params.value[1]+': '+ formatter.format(params.value[2])) }" ))
I have the same issue adding the impossibility to format label as currency.
"tibble( Year=c(1,1,1,2,2,2,3,3,3), Category=c("A","B","C","A","B","C","A","B","C"), money = c(100,200,100,200,300,200,400,150,600) ) %>% e_chart(Category) %>% e_heatmap(Year,money, label=list(show=TRUE)) %>% ..."
@CCCP-Data - as @nschwamm wrote above, you may try this:
tibble( Year=c(1,1,1,2,2,2,3,3,3), Category=c("A","B","C","A","B","C","A","B","C"),
money = c(100,200,100,200,300,200,400,150,600) ) %>%
e_chart(Category) %>%
e_heatmap(Year, money, label=list(show=TRUE,
formatter = htmlwidgets::JS("function(params){
let formatter = new Intl.NumberFormat('en-US', { style:'currency', currency:'USD', });
return(formatter.format(params.value[2])) }")))