Search code examples
recharts4r

Hide tooltip of e_mark_line


I have a similar problem as in this post. However somehow all my attempts fail. The goal is that the tooltip works on the bars, but not on the line (e_mark_line()):

library(echarts4r)
tibble::tibble(category = LETTERS[1:4],
       num1 = c(50, 100, 150, 200),
       num2 = c(1,2,3,4)) |> 
  e_charts(category) |>
  e_bar(num1, num2) |>
  e_tooltip(trigger = "item", 
            formatter = htmlwidgets::JS("
                                        function(params){
                                        return('<strong>' + params.value[0] +
                                        '</strong><br />num1: ' +  params.value[1] +
                                        '<br />num2: ' +  params.name )   }  ")
            ) |>
  e_legend(show = FALSE) |>
  e_mark_line(data = list(yAxis = 100),
              symbol = "none",
              label = list(triggerTooltip = FALSE, silent = TRUE, color = "#000000")) 

Solution

  • The issue is that you have put silent=TRUE in the wrong place, i.e. it is an attribute of e_mark_line not of label, i.e. use e_mark_line(..., silent = TRUE) to silent the tooltip for the mark line:

    Note: After a look at the docs label also has no attribute triggerTooltip so I dropped it.

    library(echarts4r)
    tibble::tibble(
      category = LETTERS[1:4],
      num1 = c(50, 100, 150, 200),
      num2 = c(1, 2, 3, 4)
    ) |>
      e_charts(category) |>
      e_bar(
        num1, num2
      ) |>
      e_tooltip(
        trigger = "item",
        formatter = htmlwidgets::JS(
          "function(params){
              return('<strong>' + params.value[0] +
                '</strong><br />num1: ' +  params.value[1] +
                '<br />num2: ' +  params.name )
              }
            "
        )
      ) |>
      e_legend(show = FALSE) |>
      e_mark_line(
        data = list(yAxis = 100),
        symbol = "none",
        label = list(color = "#000000"),
        silent = TRUE
      )