R Highcharter: tooltip customization

后端 未结 1 1588
没有蜡笔的小新
没有蜡笔的小新 2021-01-01 05:22

I created a chart using highcharter in a shiny dashboard and I am trying to customize the tooltip. The chart is combined line and scatter plot. I would like it to do the fol

相关标签:
1条回答
  • 2021-01-01 06:09

    Firt of all, you need to add all the data instead give only the vector (the vector DON´T have all the information to the tooltip you want). To do this you need change the data argument using the data.frame with the hcaes helper function in the mapping argument to define which variable use in every axis:

    highchart() %>%
      hc_add_series(data = data, mapping = hcaes(x=date, y=hours), name = "Shipments", type = "scatter", color = "#2670FF", marker = list(radius = 2), alpha = 0.5) %>%
      hc_add_series(data = data, hcaes(date, avghours), name = "Rolling Mean", type = "line", color = "#FF7900") %>%
      hc_yAxis(min = 0, title = list(text = "Hours")) %>%
      hc_tooltip(crosshairs = TRUE)
    

    Then you can use the tooltip argument in every hc_add_series to define the tooltip in each series:

    highchart() %>%
      hc_add_series(data = data, hcaes(date, hours), name = "Shipments", type = "scatter",
                    tooltip = list(pointFormat = "tooltip with 2 values {point.animal}: {point.hours}")) %>%
      hc_add_series(data = data, hcaes(date, avghours), name = "Rolling Mean", type = "line",
                    tooltip = list(pointFormat = "Avg hour text! {point.avghours}")) %>%
      hc_yAxis(min = 0, title = list(text = "Hours")) %>%
      hc_tooltip(crosshairs = TRUE)
    

    0 讨论(0)
提交回复
热议问题