【问题标题】:Displaying datatable in highcharter tooltip在 highcharter 工具提示中显示数据表
【发布时间】:2016-10-21 20:41:34
【问题描述】:

使用post 中的第一个代码块,我想创建一个工具提示,显示特定日期访问诊所的医生列表。我尝试了以下代码,但没有显示任何内容

library(DT)    
tltp = DT:: datatable(data.frame(Doctors = x[x$Clinic=="{point.series}"&x$VisitDate == "{point.x}",2]))
hc%>%hc_tooltip(pointFormat = tltp)

我也尝试过使用tooltip_table 会出错

tltp = tooltip_table(x = NULL, y = x[x$Clinic=="{point.series}"&x$VisitDate == "{point.x}",2]
hc%>%hc_tooltip(pointFormat = tltp)

Error: unexpected symbol in:
"tltp = tooltip_table(x = NULL, y = x[x$Clinic=="{point.series}"&x$VisitDate == "{point.x}",2]
tltp"

抱歉,我不擅长编写 javascript。

【问题讨论】:

  • 这不是一个简单的练习。首先tooltip_table 返回一个模板以显示在工具提示中,并使用它不会返回工具提示本身的文本。参数 ?tooltip_table xy 是字符串,而不是向量或数据表元素。我将尝试举一些例子来解释这一点。

标签: r highcharts dt


【解决方案1】:

正如官方页面推荐的那样,使用 highcharter 是不错的选择,请阅读 highchartsjs 的工作原理。因此,请使用简单的自定义工具提示查看此示例。

hc <- hchart(visits, "column", x = as.Date(VisitDate), y = freq, group = Clinic) %>% 
  hc_plotOptions(column = list(
    dataLabels = list(enabled = FALSE),
    stacking = "normal",
    enableMouseTracking = TRUE)
  ) 

使用列名添加简单的工具提示:Clinicfreq

hc %>% 
  hc_tooltip(pointFormat = "this is and clinic {point.Clinic} and freq {point.freq}")

tooltip_table的功能是在tooltip里做表格:

tt <- tooltip_table(c("Clinic", "Freq"), c("{point.series.name}", "{point.y}"))

hc %>% 
   hc_tooltip(pointFormat = tt, useHTML = TRUE)

如果您需要在工具提示中显示其他数据,您可以创建列:

visits$doctors <- sample(letters, size = nrow(visits))

然后再次创建图表(使用新数据)并在工具提示中使用此列:

hchart(visits, "column", x = as.Date(VisitDate), y = freq, group = Clinic) %>% 
  hc_plotOptions(column = list(
    dataLabels = list(enabled = FALSE),
    stacking = "normal",
    enableMouseTracking = TRUE)
  ) %>% 
  hc_tooltip(pointFormat = "Here is the doctor {point.doctors}")

【讨论】:

  • 谢谢。这让我的果汁流淌。我可以调整你的回复以获得我想要的。
  • 很高兴帮助@earthlink
  • 这就像hchart 的魅力一样,如何与highcharthc_add_series 一起使用?
  • 您需要将数据添加为列表,因此它将是hc_add_series(data = list_parse(visits))
猜你喜欢
  • 2018-11-17
  • 2019-03-09
  • 2020-03-29
  • 2021-09-07
  • 2018-04-07
  • 2018-12-07
  • 2021-03-20
  • 1970-01-01
  • 2010-10-04
相关资源
最近更新 更多