Jordan Wrong
Jordan Wrong

Reputation: 1245

Add Additional Information In Tooltip R Highcharts

I have some data that I would like to graph using highcharts. When I hover over a given point, I would like the tooltip to also include the column "type". Here is my current reproducible example.

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

Upvotes: 0

Views: 639

Answers (1)

Ben
Ben

Reputation: 30474

If you pass in dat as data in your hc_add_series function, you can access other columns in the tooltip argument, like 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}"))

highcharter with custom tooltip

Upvotes: 2

Related Questions