Highcharts motion plugin - Requires 3 adjustments到一张 Highcharts 。
- 包含js资源
motion
的选项对象- 数据在
sequence
数组中。
Highcharts
似乎有两个主要的 R
包装器。拉姆纳特的 rCharts
以及最近在 CRAN 上发布的 highcharter
.
所以我的问题是:是否可以使用当前可用的包装器随着时间的推移为气泡 Highcharts 设置动画?如果可以的话,怎么做?
rCharts 尝试 1 从气泡图开始,介绍 3 个必需的运动选项:
library(rCharts) # highcharts wrapper hPlot()
# data
set.seed(1)
df.SO <- data.frame(date = sample(2005:2016, 21, replace = T)
, x = rnorm(21, 10, 4)
, y = rnorm(21, 150, 4)
, z = rbinom(21, 80, .8)
, entities = sample(c("entity1","entity2","entity3"), 21, replace = T))
# chart
h1 <- hPlot( x = "x"
, y = "y"
, size = "z"
, group = "entities"
, data = df.SO
, type = "bubble")
### Motion Charts plugin ###
## 1. include motion js asset in head
h1$addAssets(jshead = "https://rawgit.com/larsac07/Motion-Highcharts-Plugin/master/motion.js")
## 2. add motion object
h1$params$motion <- list(enabled = "true",
labels = unique(sort(df.SO$date)),
loop = "true",
series = 1,
updateInterval = 50,
magnet = list(
round = "round",
step = 0.1))
## 3. sequence data?? Dead end approach??
# view chart - displays bubbles and widget to play animation, but animation fails
print(h1)
rCharts - 尝试 2 将数据重组为序列,然后输入图表。
# 3. sequence data - cast data so entities are series and times are unique entries
library(data.table) ## v >= 1.9.6
test <- dcast(setDT(df.SO), date ~ entities, value.var = c("x", "y", "z"))
# chart
h1 <- Highcharts$new()
h1$chart(type = "bubble", height = 300)
h1$series(
list(name = "entity1",
data = list(
sequence = test$x_length_entity1,
sequence = test$y_length_entity1,
sequence = test$z_length_entity1
)
),
list(name = "entity2",
data = list(
sequence = test$x_length_entity2,
sequence = test$y_length_entity2,
sequence = test$z_length_entity2
)
), replace = T)
## 1. include motion js asset in head
h1$addAssets(jshead = "https://rawgit.com/larsac07/Motion-Highcharts-Plugin/master/motion.js")
## 2. add motion object
h1$params$motion <- list(enabled = "true",
labels = unique(sort(test$date)),
loop = "true",
series = 1,
updateInterval = 50,
magnet = list(
round = "round",
step = 0.1))
# view chart - this approach doesn't display any bubbles
print(h1)
最佳答案
卢克,
motion.js
插件已添加到 highcharter
。处于开发版本(通过 devtools
下载),需要更多测试,但这是一个开始。
请查看http://jkunst.com/highcharter/plugins.html#motion中的示例:
highchart() %>%
hc_chart(type = "column") %>%
hc_yAxis(max = 6, min = 0) %>%
hc_add_series(name = "A", data = c(2,3,4), zIndex = -10) %>%
hc_add_series(name = "B",
data = list(
list(sequence = c(1,2,3,4)),
list(sequence = c(3,2,1,3)),
list(sequence = c(2,5,4,3))
)) %>%
hc_add_series(name = "C",
data = list(
list(sequence = c(3,2,1,3)),
list(sequence = c(2,5,4,3)),
list(sequence = c(1,2,3,4))
)) %>%
hc_motion(enabled = TRUE,
labels = 2000:2003,
series = c(1,2))
如果您发现任何可疑行为(又名错误),请在此处报告:https://github.com/jbkunst/highcharter/issues
希望对你有帮助
关于javascript - 如何使用 R 包装器为气泡图包含 highcharts 运动插件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35979227/