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

时间:2020-10-02 06:58:28

标签: highcharts polygon r-highcharter

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

enter image description here

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

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

1 个答案:

答案 0 :(得分:0)

这有点奏效:

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), data[,2], n=vertices, ...)$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函数会创建许多新点,这些新点连接到更圆的形状上:-)

相关问题