简体   繁体   English

添加相关信息 tooltip echarts4r boxplot outliers

[英]add relevant information tooltip echarts4r boxplot outliers

I am trying to add some relevant hover information to the tooltip of a echarts4r plot. I want to make an boxplot that shows the user the name (or some other information) of the outliers.我正在尝试将一些相关的 hover 信息添加到 echarts4r plot 的工具提示中。我想制作一个箱线图,向用户显示异常值的名称(或其他一些信息)。 This is somewhat related to Add extra variables to tooltip pie chart echarts4r and Add extra variables to tooltip pie chart echarts4r , but those solutions do not work as bind does not work for e_boxplot .这与Add extra variables to tooltip pie chart echarts4rAdd extra variables to tooltip pie chart echarts4r有点相关,但这些解决方案不起作用,因为binde_boxplot

This is what I have so far这是我到目前为止所拥有的

library(echarts4r)

df <- data.frame(
    my_name = letters[1:11],
    x = c(1:10, 25),
    y = c(1:10, -6)
)

df |>
    e_charts() |>
    e_boxplot(y, outliers = TRUE) |>
    e_boxplot(x, outliers = TRUE) |>
    e_tooltip(
      formatter = htmlwidgets::JS("
        function(params)
        {
          return `<strong>${params.name}</strong>
            <br/>val: ${params.value[1]}
          <br/>name: ${params.my_name}`
        }
      "))

The only way I was able to get this to work was to do it manually.我能够让它工作的唯一方法是手动完成。 I've added a debugger statement to the formatter.我已经向格式化程序添加了调试器语句。 You can print the echart and use the View in browser button:您可以打印 echart 并使用“在浏览器中查看”按钮: 在浏览器中查看

Open up the Chrome Devtools console and roll over your scatter dot and the debugger will open in your callback function for you to explore the value object and get the desired information out of it for forming your tooltip.打开 Chrome Devtools 控制台并滚动你的散点,调试器将在你的回调 function 中打开,供你探索value object 并从中获取所需信息以形成你的工具提示。 The object val will already have you y-axis value if you just want to work with that.如果您只想使用 object val ,则它已经具有您的 y 轴值。

Hope this helps!希望这可以帮助!

e <- df |>
        e_charts() |>
        e_boxplot(y, outliers = TRUE) |>
        e_boxplot(x, outliers = TRUE) |>
        e_tooltip(
          trigger = "item"
        )
      # Series 2 is the outlier scatter layer
      e$x$opts$series[[2]]$tooltip <- list(
        formatter = "(value) => {
           var val = value.value[1];
          debugger;
           // your subsequent changes
        }")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM