Every javascript charting library has its own mechanism to handle things, including click events. So in general trying to copy the approach from one library to the other will not work. Fortunately, polychart
has a mechanism for supporting click handlers. Here is a minimal example. I am essentially adding a javascript snippet using afterScript
that adds the handler to the chart. The documentation in polycharts for interaction handlers is very thin, so to do anything more meaningful you will have to dive into their source code or look at their examples.
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',
tooltip = "#!function(item){ return 'x: ' + item.x + ' y: ' + item.y + ' id: ' + item.id }!#"
)
p$set(dom = 'chart1')
p$setTemplate(afterScript = "
<script>
graph_chart1.addHandler(function(type, e){
var data = e.evtData
if (type === 'click'){
alert('You clicked on' + data.x.in[0] + ',' + data.y.in[0])
}
})
</script>
")
To make this work, you will need to install the dev
branch of rCharts
install.packages('base64enc') # dependency
devtools::install_github("ramnathv/rCharts@dev")