0
votes

I am using highcharter and I have the follwoing problem. In https://jkunst.com/highcharter/articles/stock.html at the end you have stacked charts and the tooltips for every series are shown simultaneously:

enter image description here

Assume I have the a highchart created by

require(highcharter)

pd1 <- data.frame(x=1:10,y=rnorm(10))

plt <- highchart() %>% 
  hc_add_series(pd1, "scatter", hcaes(x = x, y = y), color = "#7cb4ed",
                tooltip = list(headerFormat="<b> data1 <b> <br/>", 
                               pointFormat = "x1: {point.x} <br/> y1: {point.y}"), 
                name = "data1")

pd2 <- data.frame(x=1:10,y=rnorm(10))

plt <- plt %>% 
  hc_add_series(pd2, "line", hcaes(x = x, y = y), color = "red",
                tooltip = list(headerFormat="<b> data2 <b> <br/>", 
                               pointFormat = "x2: {point.x} <br/> y2: {point.y}"), 
                name = "data2")

plt

How can I achieve the same as in the picture, where all tooltips are shown when moving over a point? I looked at the hc_tooltip-function and found the shared, but plt %>% hc_tooltip(shared=TRUE) does not work.

1

1 Answers

2
votes

The issue is that shared tooltip shouldn't work on scatter series at all, because they are not sorted and laid out in increasing X order: https://github.com/highcharts/highcharts/issues/1431

You can find the proposed workaround here: Scatter tooltip of highchart is not being displaying

library('highcharter')
highchart() %>%
  hc_tooltip(shared=TRUE) %>%
  hc_add_series(
    type = "line",
    data = list(5, 4, 3, 5)
  ) %>%
  hc_add_series(
    type = "line",
    lineWidth = 0,
    data = list(15, 14, 13, 15)
  )