此示例展示了如何使用 javascript 向 rPlot 添加工具提示:rPlot 工具提示问题 此示例展示了如何将点击事件添加到 hPlot(highcharts): https ://github.com/ramnathv/rCharts/blob/master/inst/库/highcharts/examples.R
我想让 rPlot 执行与 hPlot 类似的 on.click 事件,但无法找出使用 rPlot/polycharts 分配它的正确方法。
Polychart 示例(成功应用工具提示):
require(rCharts)
set.seed(1)
test1 <- data.frame(x = rnorm(100), y = rnorm(100), id = 1:100)
p <- rPlot(y ~ x, data = test1,
type = 'point',
point = list(events = list(click = "#!function(item){ alert( 'x: ' + item.x +
' y: ' + item.y + ' id: ' + item.id); }!#")),
tooltip = "#!function(item){ return 'x: ' + item.x +
' y: ' + item.y + ' id: ' + item.id }!#")
p
HighCharts 示例(成功创建警报弹出窗口):
require(rCharts)
a <- hPlot(freq ~ Exer, data = plyr::count(MASS::survey, c('Sex','Exer')), type = 'bar', group = 'Sex', group.na = 'NA\'s')
a$plotOptions(bar = list(cursor = 'pointer', point = list(events = list(click = "#! function() { alert ('Category: '+ this.category +', value: '+ this.y); } !#"))))
a
下面是我当前绘制但不触发点击事件的代码:
require(rCharts)
set.seed(1)
test1 <- data.frame(x = rnorm(100), y = rnorm(100), id = 1:100)
p <- rPlot(y ~ x, data = test1,
type = 'point',
point = list(events = list(click = "#! function() {alert('testMessagePleaseWork');} !#")),
tooltip = "#!function(item){ return 'x: ' + item.x + ' y: ' + item.y + ' id: ' + item.id }!#")
p
当前使用 rCharts v0.4.2: 包:rCharts 类型:包标题:使用 Polycharts.js 的交互式图表版本:0.4.2 日期:2013-04-09