Question

I want to create a scatter plot of the movies dataset where when the user scrolls over a point, it will display the title of the movie. Using the answer from rCharts rNVD3 tooltip customisation, I wrote the following:

movies <- data(movies)
p1 <- nPlot(length ~ votes,
            group = 'mpaa', 
            data = movies, 
            type = 'scatterChart',
            #the following line seems to have NO EFFECT:
            tooltip = "#!function(item){ return item.title + ' ' + '('+item.year+')'}!#")
#item is not a valid input to the tooltipContent function
p1$chart(tooltipContent = "#! function(key, x, y){ 
            return key + ' '+item.year
            } !#")
p1$print("chart3")
p1

As noted in the in-line comments above, neither of these attempts to customize the tooltip is working for me.

Was it helpful?

Solution

You are mixing up tooltip specification for polycharts with nvd3. rCharts is merely a wrapper that lets you access functionalities within these js libraries, and since each library has a different way to let you specify tooltips, things are different. Here is how to make it work

p1$chart(tooltipContent = "#! function(key, x, y, e){ 
  return key + ' ' + e.point.year
} !#")
p1
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top