如何在R中对highcharts比较选项进行估值

5w9g7ksd  于 2022-11-10  发布在  Highcharts
关注(0)|答案(1)|浏览(184)

我有这个密码

serie <- data.frame(date=c("2022-01-01","2022-01-02","2022-01-03"),serie2=c(1,2,5), serie3=c(4,6,7))
serie$date <- as.Date(serie$date)
serie <- tk_xts(serie,data_var = serie$date)

highchart(type = "stock") %>%
  hc_title(text = "Comparison") %>%
  hc_add_series(serie$serie2,
                name = "serie 2",
                color = "green", compare = 'percent', compareBase=100) %>%
  hc_add_series(serie$serie3, name = "serie 3", color= "white",compare = 'percent', compareBase=100)%>%
  hc_add_theme(hc_theme_db())%>%
  hc_navigator(enabled = FALSE) %>%
  hc_scrollbar(enabled = FALSE) %>%
  hc_legend(enabled = TRUE) %>%
  hc_exporting(enabled = TRUE) %>%
  hc_xAxis(
    labels = list(
      style = list(
        color = "white"
      )
    )
  ) %>%
  hc_yAxis(
    labels = list(format = '{value}%',
                  style = list(
                    color = "white"
                  )
    )
  )

我需要在R-highcharts中得到这个值。我看到了这个https://www.highcharts.com/demo/stock/compare,但是我不明白代码,因为它和R有点不同。非常感谢

gr8qqesn

gr8qqesn1#

要确定您的要求有点困难。我认为您希望修改工具提示,使其与此图中记录的内容相匹配。如果是这样,您可以使用

hc_tooltip(pointFormat = paste0('<span style="color:{series.color}">{series.name}',
                                '</span>: <b>{point.y}</b> ({point.change}%)<br/>'),
           valueDecimals = 2,
           split = T)

Y轴没有标签,但您有设置其格式的代码。如果希望Y轴的格式与此图类似,可以使用

hc_yAxis(formatter = "function(){
           return (this.value > 0 ? ' + ' : '') + this.value + '%';
           }")

如果还有什么事就告诉我。

相关问题