Search code examples
rr-highcharter

R Highcharter - How to customize tooltips for multiple y-axes?


Is it possible to customize tooltip pointformat for multiple y-axes? In the simple example below, I have two y-axes: one for value and one for percentage. I want the tooltip to show ${point.y:,.0f} for the value series, and {point.y:,.2f}% for the percentage series.

highchart() %>%
  hc_yAxis_multiples(list(title=list(text="<b>Value<b>"),
                          showLastLabel = FALSE,opposite = FALSE),
                     list(title=list(text="<b>Percent<b>"),
                          showLastLabel = FALSE,  opposite = T)) %>%
  hc_add_series(c(seq(100,110)), yAxis=0) %>%
  hc_add_series(c(seq(1,10)), yAxis=1)

I tried to add hc_tooltip(list(pointFormat = "<b>{series.name}: ${point.y:,.0f}",pointFormat = "<b>{series.name}: {point.y:,.2f}%")), but it doesn't work.


Solution

  • You can specify the tooltip for each individual hc_add_series:

    highchart() %>%
      hc_yAxis_multiples(list(title=list(text="<b>Value<b>"),
                              showLastLabel = FALSE,opposite = FALSE),
                         list(title=list(text="<b>Percent<b>"),
                              showLastLabel = FALSE,  opposite = T)) %>%
      hc_add_series(c(seq(100,110)), yAxis=0,
                    tooltip = list(pointFormat = "<b>{series.name}: ${point.y:,.0f}")) %>%
      hc_add_series(c(seq(1,10)), yAxis=1,
                    tooltip = list(pointFormat = "<b>{series.name}: {point.y:,.2f}%"))