Home > Software engineering >  Is it possible to change e_line opacity in echarts4r?
Is it possible to change e_line opacity in echarts4r?

Time:05-30

I would like to change the opacity of the line in my plot made with echarts4r.

This is what I tried to do

library(quantmod)
library(echarts4r)

getSymbols("GS") #Goldman Sachs
GS <- as.data.frame(GS)
GS$date <- row.names(GS)
GS$level <- 200
GS |> 
  e_charts(date) |> 
  e_candle(GS.Open, GS.Close, GS.Low, GS.High, name = "Goldman Sachs") |> 
  e_datazoom(type = "slider") |> 
  e_title("Candlestick chart", "Quantmod data") |>
  e_line(serie = level, name = "Fib", itemStyle = list(color = "#39558CFF", opacity = 0.1), legend = T)

But opacity = 0.1 doesn't seem to work.

Some data to reproduce the example

structure(list(GS.Open = c(200.600006, 200.220001, 198.429993, 
199.050003, 203.539993, 203.399994, 208.339996, 210.899994, 210.850006, 
212.199997), GS.High = c(203.320007, 200.669998, 200, 203.949997, 
204.899994, 208.440002, 213.169998, 214.220001, 215.130005, 214.089996
), GS.Low = c(197.820007, 198.070007, 197.899994, 198.100006, 
202, 201.5, 207.600006, 210.399994, 210.850006, 210.850006), 
    GS.Close = c(200.720001, 198.850006, 199.050003, 203.729996, 
    204.080002, 208.110001, 211.880005, 213.990005, 213.589996, 
    213.229996), GS.Volume = c(6494900, 6460200, 5892900, 7851000, 
    7147100, 8025700, 9039400, 6618900, 5846600, 5306300), GS.Adjusted = c(162.160843, 
    160.65007, 160.811615, 164.592575, 164.875366, 168.131165, 
    171.17691, 172.881531, 172.558395, 172.267578), date = c("2007-01-03", 
    "2007-01-04", "2007-01-05", "2007-01-08", "2007-01-09", "2007-01-10", 
    "2007-01-11", "2007-01-12", "2007-01-16", "2007-01-17"), 
    level = c(200, 200, 200, 200, 200, 200, 200, 200, 200, 200
    )), row.names = c("2007-01-03", "2007-01-04", "2007-01-05", 
"2007-01-08", "2007-01-09", "2007-01-10", "2007-01-11", "2007-01-12", 
"2007-01-16", "2007-01-17"), class = "data.frame")

CodePudding user response:

You should you lineStyle instead of itemStyle like this:

library(quantmod)
library(echarts4r)

getSymbols("GS") #Goldman Sachs
getSymbols("GS",from="2018-02-01") #Goldman OHLC from yahoo 
GS <- as.data.frame(GS)
GS$date <- row.names(GS)
GS$level <- 200
GS |> 
  e_charts(date) |> 
  e_candle(GS.Open, GS.Close, GS.Low, GS.High, name = "Goldman Sachs") |> 
  e_datazoom(type = "slider") |> 
  e_title("Candlestick chart", "Quantmod data") |>
  e_line(serie = level, name = "Fib", lineStyle = list(color = "#39558CFF", opacity = 0.1), legend = T)

Output:

enter image description here

  • Related