3
votes

Looking to change the format of the datetime in the tooltip. I successfully did it for the x-axis but have not for the tooltip. I've read the docs and cannot find another R-specific topic on this.

Dates are in the required Highchart timestamp from the datetime_to_timestamp function.

library(highcharter)
library(tidyverse)

df <- data.frame(dateTime = c(1557705900000,1557705960000,1557706020000,1557706860000,1557706920000),
                 points = c(5,7,3,2,9))

highchart() %>%
  hc_xAxis(type = "datetime", dateTimeLabelFormats = list(day = '%H:%M')) %>%
  hc_add_series(df, type = "scatter",
                hcaes(x = dateTime, y = points)) %>% 
  hc_tooltip(crosshairs = TRUE, dateTimeLabelFormats = list(day = '%H:%M'))

# highchart() %>%
#   hc_xAxis(type = "datetime", dateTimeLabelFormats = list(day = '%H:%M')) %>%
#   hc_add_series(df, type = "scatter",
#                 hcaes(x = dateTime, y = points)) %>% 
#   hc_tooltip(crosshairs = TRUE, dateTimeLabelFormats = '%H:%M')

The tooltip format should look like the x-axis format.

enter image description here

Any thoughts?

1

1 Answers

4
votes

Try pointFormat.

highchart() %>%
  hc_xAxis(type = "datetime", dateTimeLabelFormats = list(day = '%H:%M')) %>%
  hc_add_series(df, type = "scatter",
                hcaes(x = dateTime, y = points)) %>% 
  hc_tooltip(crosshairs = TRUE, pointFormat = "x: {point.x:%H:%M} <br> y: {point.y}")