0
df1 <- data.frame(Date = c(1,2,3),
                  Reach = c(12,15,20),
                  Cost = c(12332,321112,4231223))
df1 %>% 
  e_chart(Date) %>% 
  e_bar(Reach, emphasis = list(label = list(show = FALSE))) %>% 
  e_line(Cost, y_index = 1) %>% 
  e_tooltip() %>% 
  e_title("Actual v CPC") %>% 
  e_labels(
    formatter = htmlwidgets::JS("
      function(params){
        if (params.seriesIndex == 1) {
          var cost = params.value[1];
          return 'Rp' + cost.toLocaleString('id-ID');
        } 
      }
    ")
  ) |> e_toolbox_feature(feature = "saveAsImage")

so i have this code with e_labels formatter to bring up the labels from e_line to form IDR or indonesian currency but i want to make the labels inside the bar disappear. I have tried using emphasis = list(label = list(show = False)) but it still doesn't work

the result from the code is like this enter image description here

I want the labels from the e_bar dissapear but the e_line is still showing

Phil
  • 7,287
  • 3
  • 36
  • 66

1 Answers1

0

I would suggest you don't use e_labels, but use the label parameter inside the chart function from which you want the labels to be shown.

like this:

library(echarts4r)
df1 <- data.frame(Date = c(1,2,3),
                  Reach = c(12,15,20),
                  Cost = c(12332,321112,4231223))
df1 %>% 
  e_chart(Date) %>% 
  e_bar(Reach) %>% 
  e_line(Cost, y_index = 1,
         label = list(show = TRUE,
         formatter = htmlwidgets::JS("
      function(params){
          var cost = params.value[1];
          return 'Rp' + cost.toLocaleString('id-ID');
        }"))) %>% 
  e_tooltip() %>% 
  e_title("Actual v CPC") %>% 
  e_toolbox_feature(feature = "saveAsImage")
rdatasculptor
  • 8,112
  • 14
  • 56
  • 81