echarts4r icon indicating copy to clipboard operation
echarts4r copied to clipboard

Problem with e_formatter for e_heatmap

Open nschwamm opened this issue 5 years ago • 3 comments

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) working

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.

glitchy

Any help would be great!

nschwamm avatar Feb 27 '20 16:02 nschwamm

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])) }" ))

nschwamm avatar Feb 27 '20 16:02 nschwamm

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)) %>% ..."

image

CCCP-Data avatar Jun 29 '20 22:06 CCCP-Data

@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])) }")))

helgasoft avatar Jul 22 '20 23:07 helgasoft