R - highcharter - 显示的选择性图例

R - highcharter - selective legends at display

我不确定这是否可以在 highcharter 中完成,但是,我有一个场景,我绘制了 7 个系列,默认情况下我只需要显示 3 个,但是剩余的 4 个应该显示为灰色但存在, 如果需要,用户可以单击 select。

那么,我们该怎么做呢?欢迎所有建议。我做了一些研究,但是我无法获得任何线索。

谢谢!

hc <- highchart(type = "stock") %>% 
    hc_title(text = paste0("<span style=\"color:#000000\">", prod_line, ", ", sku , " at ", cust_group ,  "</span>")) %>%
    hc_subtitle(text = paste0("<span style=\"color:#000000\">",  prod_mktg_name, "</span>")) %>%
    hc_yAxis_multiples(yaxis) %>%
    hc_add_series(yAxis = 0, name = "Retail Price", candle_data, type = "candlestick", color = "white") %>%
    hc_add_series(yAxis = 0, name = "COGS($)" , data = my_xts_data$COGS_dollar, color = "blue") %>% 
    hc_add_series(yAxis = 0, name = "MSRP", data = my_xts_data$MSRP, color = "black") %>%
    hc_add_series(yAxis = 0, name = "Sell In Price", data = my_xts_data$SI_price, color = "orange") %>%
    hc_add_series(yAxis = 1, name = "Sell In Units", data = my_xts_data$SI_units, color = "orange", type = "column") %>%
    hc_add_series(yAxis = 1, name = "Channel Inv Units", data = my_xts_data$CI_units, color = "gray", type = "column") %>%
    hc_add_series(yAxis = 1, name = "Sell Thru Units", data = my_xts_data$ST_units, color = "black", type = "column") %>%
    hc_legend(enabled = TRUE) %>%
    hc_exporting(enabled = TRUE) %>%
    hc_tooltip(shared = TRUE) 

hc

您可以将参数 'visible = FALSE' 添加到 hc_add_series 函数

https://api.highcharts.com/highcharts/plotOptions.series.visible

修改自下方 http://jkunst.com/highcharter/highstock.html 的 Highcharter 示例

library("quantmod")

usdjpy <- getSymbols("USD/JPY", src = "oanda", auto.assign = FALSE)
eurkpw <- getSymbols("EUR/KPW", src = "oanda", auto.assign = FALSE)

hc <- highchart(type = "stock") %>% 
  hc_title(text = "Charting some Symbols") %>% 
  hc_subtitle(text = "Data extracted using quantmod package") %>% 
  hc_add_series(usdjpy, id = "usdjpy") %>% 
  hc_add_series(eurkpw, id = "eurkpw", visible = FALSE) %>%
  hc_legend(enabled = TRUE)