R - highcharter - selective legends at display

女生的网名这么多〃 提交于 2021-01-28 07:02:30

问题


I am not sure whether this could be done in highcharter, however, I have a scenario where I have 7 series plotted of which by default I need to display only 3, however remaining 4 should be greyed out but be present, user can click and select if needed.

So, how can we do that? All suggestions are welcome. I did some research, however i was not able to get any leads.

Thanks!

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

回答1:


You can add the argument 'visible = FALSE' to the hc_add_series functions

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

Highcharter example modified from http://jkunst.com/highcharter/highstock.html below

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)


来源:https://stackoverflow.com/questions/56447985/r-highcharter-selective-legends-at-display

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!