Debian Codegraph @

demo/EventListener.R

raw
1 ## The parameter gvis.listener.jscode embeds code inside
2 ## a select event listener.
3 ## It is possible to add javascript code and access the build in
4 ## method getSelection().
5 ##
6 ## The following code shows two examples:
7
8 jscode <- "window.open('https://en.wikipedia.org/wiki/'+data.getValue(chart.getSelection()[0].row,0)); "
9 J1 <- gvisGeoMap(Exports, locationvar='Country', numvar='Profit',
10 options=list(dataMode="regions",gvis.listener.jscode=jscode))
11
12 plot(J1)
13 ## Similarly the code can also be used for other charts, e.g. org chart and line chart
14
15 plot(gvisOrgChart(Regions, options=list(gvis.listener.jscode=jscode)))
16
17 plot(gvisLineChart(Regions[,c(1,3)], options=list(gvis.listener.jscode=jscode)))
18
19
20 jscode <- "
21 var sel = chart.getSelection();
22 var row = sel[0].row;
23 var text = data.getValue(row,1);
24 alert(text);
25 "
26
27 J2 <- gvisTable(Population,options=list(gvis.listener.jscode=jscode))
28
29 plot(J2)
30
31 ## For more details see
32 ## https://developers.google.com/chart/interactive/docs/reference?csw=1#addlistener
33
34 ## See demo(package='googleVis') for other available demos.