Skip to content

Instantly share code, notes, and snippets.

@helgasoft
Last active October 9, 2025 07:52
Show Gist options
  • Save helgasoft/e914fe6f4a9ed9407f78e41cb18b3aaa to your computer and use it in GitHub Desktop.
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) )
)
@tomroh
Copy link

tomroh commented Oct 9, 2025

Thanks! What's the code with echarts4r?

@helgasoft
Copy link
Author

helgasoft commented Oct 9, 2025

No idea how echarts4r could handle it.
Here is how to make a responsive custom polygon with echarty.

renit <- "function(params, api) {
      // Get the current data item (one vertex)
      const x = api.value(0, params.dataIndexInside);
      const y = api.value(1, params.dataIndexInside);
      if (!Number.isNaN(x)) {
        // collect points until ['the','end']
        polypnts.push(api.coord([x,y])); 
        return;
      }
      locp = echarts.util.clone(polypnts);
      polypnts = [];  // prepare to rerender on resize
      return {
        type: 'polygon',
        shape: { points: locp },
        style: api.style({
          fill: api.visual('color'),
          stroke: 'red',
          lineWidth: 2
        })
      };
    }"
df <- data.frame(
  x= c(100,350,100,NA),
  y= c(100,100,200,NA)
)
ec.init( df,
  js= c('window.polypnts=[];','',''),  # init points storage in JS
  series.param= list(type= 'custom', renderItem= ec.clmn(renit) )
)
image

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