【问题标题】:Formatting datetime in Highcharter tooltip在 Highcharter 工具提示中格式化日期时间
【发布时间】:2019-10-05 03:35:25
【问题描述】:

希望更改工具提示中日期时间的格式。我成功地为 x 轴做到了,但没有为工具提示。我已阅读文档,找不到关于此的另一个 R 特定主题。

日期位于 datetime_to_timestamp 函数所需的 Highchart 时间戳中。

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')

工具提示格式应该类似于 x 轴格式。

有什么想法吗?

【问题讨论】:

    标签: r highcharts r-highcharter


    【解决方案1】:

    试试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}")
    

    【讨论】:

      猜你喜欢
      • 2018-12-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-17
      • 2017-11-29
      • 1970-01-01
      相关资源
      最近更新 更多