R-Highcharter-展出的精选图例

时间:2019-06-04 16:32:41

标签: r highcharts legend legend-properties r-highcharter

我不确定是否可以在高级图表中完成此操作,但是,我有一个场景,其中绘制了7个系列,默认情况下,我只需要显示3个,但是其余4个应该显示为灰色,用户可以单击并根据需要选择。

那么,我们该怎么做呢?欢迎所有建议。我做了一些研究,但是却找不到任何线索。

谢谢!

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 个答案:

答案 0 :(得分:2)

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

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

从下面的http://jkunst.com/highcharter/highstock.html修改的高级章程示例

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)