Search code examples
rhighchartsr-highcharter

show value if multiple y values on xAxis are used


I have multiple y values for same x-value, Everything works fine except mousehovering. With the code above, it shows just the value of one point, instead of a value for each point. I think they had a similar problem here https://github.com/highcharts/highcharts/issues/6231.

library("highcharter")
df1 <- data.frame(x = c(0,0,1,2,2,3,4),
              y = c(50,100,100,105,150,110,120),
              name = c("A","A","A","A","A","A","A"),
              findNearestPointBy= 'xy')

df2 <- data.frame(x = c(3:6),
              y = c(80,90,98,105),
              name = c("B","B","B","B"),
              findNearestPointBy= 'xy')
series_list <- list(df1, df2)


hc2 <- highchart()
for (k in 1:length(series_list)) {
hc2 <- hc2 %>%
hc_add_series(series_list[[k]])
}
hc2

so if the curser is around x=0, tooltip always shows 100 and never 50, is it not possible to show 50 if I'm close to 50 with my cursor?

Appreciate any help!


Solution

  • I have it:

    library("highcharter")
    df1 <- data.frame(x = c(0,0,1,2,2,3,4),
                  y = c(50,100,100,105,150,110,120),
                  name = c("A","A","A","A","A","A","A"),
                  findNearestPointBy= 'xy')
    
    df2 <- data.frame(x = c(3:6),
                  y = c(80,90,98,105),
                  name = c("B","B","B","B"),
                  findNearestPointBy= 'xy')
    series_list <- list(df1, df2)
    
    
    hc2 <- highchart()%>%
    hc_plotOptions(line = list(findNearestPointBy = 'xy'))
    for (k in 1:length(series_list)) {
        hc2 <- hc2 %>%
        hc_add_series(series_list[[k]])
    
    }
    hc2
    

    Maybe somebody else had the same problem in the past!