Skip to content

Instantly share code, notes, and snippets.

@helgasoft
Last active December 3, 2025 21:42
Show Gist options
  • Select an option

  • Save helgasoft/e914fe6f4a9ed9407f78e41cb18b3aaa to your computer and use it in GitHub Desktop.

Select an option

Save helgasoft/e914fe6f4a9ed9407f78e41cb18b3aaa to your computer and use it in GitHub Desktop.
echarty announcements and temporary notes
#' This gist is for echarty announcements and notes
#' Comments are temporary, periodically deleted.
#' If you like echarty, please consider granting a Github star ⭐.
remotes::install_github('helgasoft/echarty') # get latest
library(echarty)
#------ segmentedDoughnut with ECharts v.6+ -----
ec.init(
load= 'https://cdn.jsdelivr.net/gh/apache/echarts-custom-series@main/custom-series/segmentedDoughnut/dist/index.auto.js',
ask= 'loadRemote',
series.param= list(
type= 'custom', renderItem= 'segmentedDoughnut',
coordinateSystem= 'none',
itemPayload= list(
radius= list('50%','65%'), segmentCount= 8,
label= list(show=T, formatter= '{c}/{b}', fontSize=35, color= '#555')
),
data= list(5) )
)
@helgasoft
Copy link
Author

@gumeo, 100% stacked bar chart is doable in echarty

# from official example https://echarts.apache.org/examples/en/editor.html?c=bar-stack-normalization
txt <- "Direct,Mail Ad,Affiliate Ad,Video Ad,Search Engine
100,320,220,150,820
302,132,182,212,832
301,101,191,201,901
334,134,234,154,934
390,90,290,190,1290
330,230,330,330,1330
320,210,310,410,1320"
rawData <- read.csv(header=T, text=txt) |>
  mutate(total = rowSums(across(everything()), na.rm= TRUE)) |>   # total
  mutate(across(everything() & -total, ~ .x / total), total=NULL) # normalize

sers <- unname(lapply(rawData, \(cc) {
  list(
    name= colnames(rawData)[parent.frame()$i[]], 
    type= 'bar', stack= 'total', barWidth= '60%',
    label= list(show= T, formatter= ec.clmn("(params) => Math.round(params.value * 1000) / 10 + '%'")),
    data= cc
  )
}))
# remotes::install_github('helgasoft/echarty')    # get latest
library(echarty)
ec.init(
  legend= list(selectedMode=F), tooltip= list(show=T),
  xAxis= list(
    type= 'category',
    data= c('Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun')
  ),
  series= sers
)

If you like echarty, please consider granting a Github star ⭐.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment