如何在echarts4r中将鼠标悬停在e_mark_line中的标签上时禁用工具提示

ikfrs5lh  于 2022-12-20  发布在  Echarts
关注(0)|答案(1)|浏览(177)

我在echarts4r中构建了一个散点图,并添加了一条标记线来表示平均值,该标记线带有一个指示轴的平均值的标签。然而,当鼠标悬停在标签上时,图表中某个项目的工具提示出现了。到目前为止,我删除它的所有尝试都失败了。
感谢任何人能帮助我解决这个问题。下面是一个解决这个问题的代码示例。

library(dplyr)
library(plyr)
library(echarts4r)

mydata <- data.frame(Sector_Description= c('Wood','Vehicle', 'Vegetables'),
                     y = c(10, 8, 16),
                     x = c(5,7, 3),
                     tradevalue = c(316, 266, 356))

avg_y <- mean(mydata[,2])

mydata %>%
  e_charts(x) %>%
  e_scatter(
    y,
    tradevalue,
    label = list(
      show = TRUE,
      color = "black",
      fontSize = 10,
      position = "right",
      formatter = htmlwidgets::JS(
        "function(params){
          return(params.data.sector.Sector_Description)
                          }"
      )
    ),
    labelLayout = list(hideOverlap = TRUE, dy = 0)
  )  %>%
  e_add_nested('sector', Sector_Description) |>
  e_tooltip(
    trigger= 'item',formatter = htmlwidgets::JS("function(params){
       return(
      '<strong>Sector: </strong>' + params.data.sector.Sector_Description +
   '<br/><strong>X: </strong>' + (params.value[0]) +
    '<br/><strong>Y: </strong>' +  (params.value[1]) )   }  "
    )
  ) %>% e_hide_grid_lines() %>%
  e_y_axis(
           axisLine = list(lineStyle = list(color = "#F0F0F0")),
           axisLabel = list(color = "#000000" )
  ) %>%
  e_x_axis(
    axisLine = list(lineStyle = list(color = "#F0F0F0")),
    axisLabel = list(color = "#000000")
  ) %>%
  e_mark_line(symbol = "none",emphasis = list(disabled = TRUE),
              label = list(triggerTooltip = FALSE,
                color = "#000000",silient= FALSE),
              data = list(yAxis =avg_y ))
g6ll5ycj

g6ll5ycj1#

在调用工具提示时,您为标签写了不应静音的内容。这是您将"标记"行的工具提示"静音"的入场券。
看看吧:

mydata %>% 
  e_charts(x) %>%
  e_scatter(
    y, tradevalue, 
    label = list(
      show = TRUE, color = "black", fontSize = 10, position = "right",
      formatter = htmlwidgets::JS(
        "function(params){
          return(params.data.sector.Sector_Description)
         }")),
    labelLayout = list(hideOverlap = TRUE, dy = 0))  %>%
  e_add_nested('sector', Sector_Description) |>
  e_tooltip(
    trigger= 'item',
    formatter = htmlwidgets::JS(
      "function(params){
        return(
          '<strong>Sector: </strong>' + 
          params.data.sector.Sector_Description +
          '<br/><strong>X: </strong>' + (params.value[0]) +
          '<br/><strong>Y: </strong>' + (params.value[1]))
        }")) %>% e_hide_grid_lines() %>%
  e_y_axis(
    axisLine = list(lineStyle = list(color = "#F0F0F0")),
    axisLabel = list(color = "#000000" )) %>%
  e_x_axis(
    axisLine = list(lineStyle = list(color = "#F0F0F0")),
    axisLabel = list(color = "#000000")) %>%
  e_mark_line(symbol = "none",emphasis = list(disabled = TRUE),
              label = list(triggerTooltip = FALSE,
                           color = "#000000", silent = T), # <-- spelling & TRUE
              data = list(yAxis =avg_y))

相关问题