score:1

Accepted answer

after several years, i have an answer.

it seems like these wrapper functions like hplot() does not support additional tooltip variables even with a simple custom formatter function. see working example below based on the dataset from the question.

require(rcharts)
# create data frame
df <- data.frame(x = c(1:5), y = c(5:1), 
                 z = c("a", "b", "c", "d", "e"),
                 name = c("k", "l", "m", "n", "o"))

# plot using hplot() approach
h1 <- hplot(x = "x", y = "y", data = df, type = "scatter", group = "z")
h1$tooltip(borderwidth=0, followpointer=true, followtouchmove=true, shared = false,
           formatter = "#! function(){return 'x: ' + this.point.x + '<br>y: ' + this.point.y + '<br>z: ' + this.point.z + '<br>name: ' + this.point.name;} !#")
h1

hplot-rcharts

tooltips do not work in the above example because the variables in the array are not named. see str(h1).

# plot using manual build
h1 <- rcharts:::highcharts$new()
dlev <- levels(factor(as.character(df$z)))
for(i in 1:length(dlev))
{
  h1$series(data = tojsonarray2(df[df$z==dlev[i],,drop=f], json = f,names=t), name = dlev[i],type = c("scatter"), marker = list(radius = 3))
}
h1$tooltip(borderwidth=0, followpointer=true, followtouchmove=true, shared = false,
           formatter = "#! function(){return 'x: ' + this.point.x + '<br>y: ' + this.point.y + '<br>z: ' + this.point.z + '<br>name: ' + this.point.name;} !#")
h1

manual-build-rcharts

this works because the array variables are named using names=t in the line starting h1$series.... see str(h1).

this sort of solves the tooltip issue, but there might be other problems with the named arrays. for example, it breaks things in a shiny-app environment. there must be a reason why hplot() does not use the named arrays.

score:3

rcharts is a great package. but it still not well documented(maybe i miss this point). i think you need to redefine new js function for tooltip attribute. any js literals need to be wrapped between #! and !# . here a beginning but it doesn't work as i imagine ( i think is a good start):

h1$tooltip( formatter = "#! function() { return 'x: '     + this.point.x + 
                                                'y: '    + this.point.y  + 
                                                'name: '  + this.point.group; } !#")

Related Query

More Query from same tag