0
votes

I'm trying to customize the tooltip for the rCharts nvd3 piechart, but when I use the code below, the chart doesn't render. I am wondering if adjusting tooltips for nvd3 piecharts work differently than for other nvd3 charts? Any insight would be greatly appreciated!

here's the code I ran:

pie.sum$CATEGORY = c('Cat1','Cat2','Cat3','Cat4')
pie.sum$VALUE = c(124,55,275,20)
pie.sum$PERCENT = round((pie.sum$VALUE/sum(pie.sum$VALUE)) * 100,2)

n3 = nPlot(x = "CATEGORY", y = "VALUE", data = pie.sum, type = "pieChart")
n3$chart(tooltipYContent = NA, tooltipYContent = NA)
n3$chart(tooltipContent = "#! function(key, x, y, e){ 
return 'Category: ' + x +
'
Value' + y +
'
% of value: ' + e.point.PERCENT
} !#")
n3$set(width = 800, height = 500) # mk changed width to 800 and height to 500
n3
1

1 Answers

2
votes

You can do like this :

pie.sum = data.frame(CATEGORY = c('Cat1','Cat2','Cat3','Cat4'),
                     VALUE = c(124,55,275,20))
pie.sum$PERCENT = round((pie.sum$VALUE/sum(pie.sum$VALUE)) * 100,2)

library(rCharts)
n3 = nPlot(x = "CATEGORY", y = "VALUE", data = pie.sum, type = "pieChart")
n3$chart(tooltipContent = "#! function(key, y, e, graph){return '<h3>' + 'Category: ' + key + '</h3>' + '<p>'+ 'Value ' + y + '<br>' + ' % of value: ' + e.point.PERCENT} !#")
n3$set(width = 800, height = 500) # mk changed width to 800 and height to 500
n3