Highcharts / HighcharteR-绘制带有圆角的多边形

问题描述

library(highcharter)
highchart() %>% 
  hc_add_series(name='polygon',type='polygon',data=list(c(1,4),c(2,c(3,3),3)),borderRadius = 10,lineColor = "red",linewidth = 3)][1]][1]

enter image description here

大家好。我使用多边形来显示一些数据。我希望边界是圆形的,但是borderRadius属性对多边形不起作用。

有人知道如何对我的多边形的圆形外观进行归档吗?在这种情况下,文档没有帮助:-(。这是R Highcharter程序包,但是我也可以使用本地JS库中的示例完全满意。 谢谢!

解决方法

这有点奏效:

spline.poly <- function(xy,vertices,k=3,...) {
  # Assert: xy is an n by 2 matrix with n >= k.
  
  # Wrap k vertices around each end.
  n <- dim(xy)[1]
  if (k >= 1) {
    data <- rbind(xy[(n-k+1):n,],xy,xy[1:k,])
  } else {
    data <- xy
  }
  
  # Spline the x and y coordinates.
  data.spline <- spline(1:(n+2*k),data[,1],n=vertices,...)
  x <- data.spline$x
  x1 <- data.spline$y
  x2 <- spline(1:(n+2*k),2],...)$y
  
  # Retain only the middle part.
  cbind(x1,x2)[k < x & x <= n+k,]
}


  X <- matrix(c(resultdf$yAxis,resultdf$xAxis),ncol=2)
  hpts <- chull(X) # Creates indices of a convex hull from a matrix
  hpts <- c(hpts,hpts[1]) # connect last and first dot
  hpts <- data.frame(X[hpts,])
  hpts <- data.frame(spline.poly(as.matrix(data.frame(hpts$X1,hpts$X2)),500)) %>%
    setNames(c("yAxis","xAxis"))

spline.poly函数会创建许多新点,这些新点连接到更圆的形状上:-)