1

我正在尝试将自定义选项传递给chartJSRadar每个http://www.chartjs.org/docs/#chart-configuration-creating-a-chart-with-options。在此示例中,我尝试传递一个简单的标题,但遇到此错误:

Error in validateCssUnit(sizeInfo$width) : CSS units must be a single-element numeric or character vector

示例代码:

library(radarchart)

labs <- c("Communicator", "Data Wangler", "Programmer",
          "Technologist",  "Modeller", "Visualizer")

scores <- list(
  "Rich" = c(9, 7, 4, 5, 3, 7),
  "Andy" = c(7, 6, 6, 2, 6, 9),
  "Aimee" = c(6, 5, 8, 4, 7, 6)
)


opList <- list(title=list(display='true', text='Title'))
chartJSRadar(scores = scores, labs = labs, maxScale = 10, opList)
4

1 回答 1

1

我相信你只需要opList稍微改变你的论点。 chartJSRadar用作...传递附加选项的地方。在您的代码中,opList假定为width参数。一般来说,我会说大多数都htmlwidgets放在height最后width,所以这不会发生,但chartJSRadar不遵循这个约定。

这应该有效,但它没有,因此探索错误的来源。似乎它所基于的旧版本chartJS不提供title. 我添加了代码来展示如何手动添加title.

library(radarchart)

labs <- c("Communicator", "Data Wangler", "Programmer",
          "Technologist",  "Modeller", "Visualizer")

scores <- list(
  "Rich" = c(9, 7, 4, 5, 3, 7),
  "Andy" = c(7, 6, 6, 2, 6, 9),
  "Aimee" = c(6, 5, 8, 4, 7, 6)
)


chartJSRadar(
  scores = scores, labs = labs, maxScale = 10,
  title = list(display = TRUE, text = "Custom Title")
)

我很快整合了一个你可以尝试的更新,但它还没有经过测试,还没有准备好拉取。

devtools::install_github("timelyportfolio/radarchart@update/2.1.6")
于 2016-07-18T18:48:35.583 回答