在工具提示R高图中添加其他信息

问题描述 投票:0回答:1

我有一些要使用图表绘制的数据。当我将鼠标悬停在给定点上时,我希望工具提示也包括“类型”列。这是我当前可复制的示例。

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")

enter image description here

javascript r highcharts r-highcharter
1个回答
0
投票

如果在dat函数中以data的形式传递hc_add_series,则可以访问tooltip参数中的其他列,例如type

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}"))
© www.soinside.com 2019 - 2024. All rights reserved.