【问题标题】:Additional tooltip information in highcharter stock高租股票中的附加工具提示信息
【发布时间】:2021-06-08 10:28:41
【问题描述】:

我目前正在构建一个应用程序,我希望在高价股票中包含工具提示以及其他信息。

#Data
df <- data.frame(time = seq(as.Date("2021-03-10"), length = 10, by = "days"),
                 values = 1:10,
                 additionalInfo1 = LETTERS[1:10],
                 additionalInfo2 = letters[1:10])

#Packages
library(highcharter) #plots
library(xts) #conversion for stock-highchart
library(dplyr) #piping-operator

我知道在使用type="line" 时如何向工具提示添加附加信息。这可以通过

highchart_line <- hchart(df, "line", hcaes(x = time, y = values), 
                         tooltip = list(headerFormat = "<b> Some Tooltipheader </b> <br/>",
                                        pointFormat = paste0("index: {point.index} <br/>",
                                                             "time: {point.time} <br/>", 
                                                             "additional1: {point.additionalInfo1} <br/>",
                                                             "additional2: {point.additionalInfo2}")))

并显示一切正常。好处是可以提供全部数据,因此可以访问列名。

创建type="stock" 时,我需要将数据转换为xts,同时只使用时间和值:

stockdata_xts <- xts(x = df$values, order.by = df$time)
highchart_stock <- highchart(type="stock") %>% 
  hc_add_series(stockdata_xts, name = "someData",
                tooltip = list(pointFormat = paste0(
                  "point.x: {point.x} <br/>",
                  "point.y: {point.y} <br/>",
                  "point.index: {point.index} <br/>"
                ))) %>% 
  hc_rangeSelector(enabled = FALSE)

有没有办法将工具提示的附加数据放在股票高位图表中,使工具提示看起来像上面折线图中的那个?也许xts-object 的某些功能包括更多我不知道的属性。

我想使用stock-highchart 的原因是导航栏。如果有办法在line-highchart 中包含导航栏,我也将不胜感激。还有一个函数highcharter::hc_navigator,但文档说它只适用于highstocks。 (参见https://cloud.r-project.org/web/packages/highcharter/highcharter.pdf,第 50 页)

【问题讨论】:

    标签: r highcharts r-highcharter


    【解决方案1】:

    是的,导航器在 stockChart 中工作。对于这样的tooltip自定义,我认为最好使用专用的formatter API函数:https://api.highcharts.com/highstock/tooltip.formatter

    在这里你可以找到一篇可以帮助你在 R 中使用 JS 代码的文章: https://www.highcharts.com/blog/tutorials/working-with-highcharts-javascript-syntax-in-r/?fbclid=IwAR1Em2yNUsIJunTRS4IEbUwGksb5PC7LfZATLcyvb7uLS7ZvV7v4-e0L0

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-06
      相关资源
      最近更新 更多