highcharts 在R中的Highchart中,如何编辑当我们将鼠标悬停在散点图中的点上时显示的标签

wsxa1bj1  于 2022-11-10  发布在  Highcharts
关注(0)|答案(1)|浏览(246)

这是我的数据框和高线图:

df1 <- structure(list(col1 = c("A", "B", "C", "D", "E", "F"), col2 = c(3.54172960518873, 
4.51316494632718, 8.83778709982866, 8.9301479840624, 12.5459778934778, 
12.7053222878864)), row.names = c(NA, -6L), class = c("tbl_df", 
"tbl", "data.frame"))

df1 %>% 
    hchart(
        "scatter",
        hcaes(x = col1, y = round(col2,2)),
        showInLegend = TRUE,
        color = "#63696b",
        name = "Title 1"
    ) %>%
    hc_title(text ="RMSE",
             align = "center",
             style = list(fontSize = "18px",
                          fontFamily = "Roboto Condensed", 
                          fontWeight = "bold")) %>%

    hc_yAxis(
        title = list(text = glue::glue("Title 2"),
                     name = "RMSE",
                     style = list(fontSize = "12px",
                                  color =  "black",
                                  fontWeight = "900",
                                  fontFamily = "Roboto Condensed"),
                     labels = list(enabled = TRUE)

        ))

当我悬停在点A我有这样的信息贝娄:

我想编辑它。例如,我如何将y更改为A并删除x
有什么帮助吗?

pcrecxhr

pcrecxhr1#

使用tooltip.formatter(或者也可以使用tooltip.pointFormatter),您可以在其中传递自定义JS代码来设置工具提示的格式。

范例:

hc_tooltip(formatter = JS("function(){
  return this.key +': <b>' + this.y + '</b>'                          
"))

JS演示:https://jsfiddle.net/BlackLabel/fp85rgte/
API参考:https://api.highcharts.com/highcharts/tooltip.formatterhttps://api.highcharts.com/highcharts/tooltip.pointFormatter

相关问题