首页 > 解决方案 > 在 Tooltip R Highcharts 中添加附加信息

问题描述

我有一些数据想用 highcharts 绘制。当我将鼠标悬停在给定点上时,我希望工具提示还包括“类型”列。这是我当前的可重现示例。

library(highcharts)
dat = data.frame(first = rnorm(10), second = rnorm(10), type = rep(c("AAPL", "MSFT"),5))

highchart()%>%
            hc_xAxis(categories = dat$Open_Date)%>%
            hc_add_series(name = "first", data = dat$first, type = "column")%>%
            hc_add_series(name = "second", data = dat$second, type = "line")

在此处输入图像描述

标签: javascriptrhighchartsr-highcharter

解决方案


如果您在函数中传入,dat则可以访问参数中的其他列,例如:datahc_add_seriestooltiptype

library(highcharter)

dat = data.frame(first = rnorm(10), second = rnorm(10), type = rep(c("AAPL", "MSFT"),5))

highchart()%>%
  #hc_xAxis(categories = dat$Open_Date)%>%
  hc_add_series(name = "first", data = dat, hcaes(y = first), type = "column", 
                tooltip = list(pointFormat = "{point.type}: {point.first}"))%>%
  hc_add_series(name = "second", data = dat, hcaes(y = second), type = "line",
                tooltip = list(pointFormat = "{point.type}: {point.second}"))

带有自定义工具提示的 highcharter


推荐阅读