在highcharter工具提示中显示数据表 [英] Displaying datatable in highcharter tooltip

查看:182
本文介绍了在highcharter工具提示中显示数据表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用此帖子中的第一个代码块我想创建一个工具提示,可以显示在某一天访问诊所的医生名单。我尝试了下面的代码,它不显示任何内容

Using the first block of code in this post I want to create a tooltip that would display the list of doctors visiting a clinic on a particular day.I tried the following code which displays nothing

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

I也尝试使用 tooltip_table ,它会给出错误

I also tried using the tooltip_table which gives error

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"

流利的wri ting javascript。

Apologies I am not fluent in writing javascript.

推荐答案

正如官方页面所建议的,使用highcharter是很好的选择,请阅读highchartsjs的工作方式。所以,看看这个例子中有一个简单的自定义工具提示。

As the official page recommend, to use highcharter is good alternative read how highchartsjs works. So, see this example with a simple custom tooltip.

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

使用列添加简单工具提示姓名:诊所 freq

Adding the simple tooltip using the column names: Clinic and freq

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

tooltip_table 函数用于在工具提示中创建表格:

The tooltip_table function is to make tables in the tooltip:

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

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

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

If you need other data to show in the tooltip you can create the columun:

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

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

And then create the chart again (using the new data) and use this column in the tooltip:

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

这篇关于在highcharter工具提示中显示数据表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆