【问题标题】:rCharts pie chart - customize tooltopreCharts 饼图 - 自定义工具提示
【发布时间】:2014-12-11 02:16:00
【问题描述】:

我正在尝试自定义 rCharts nvd3 饼图的工具提示,但是当我使用下面的代码时,图表不会呈现。我想知道为 nvd3 饼图调整工具提示的工作方式是否与其他 nvd3 图表不同?任何见解将不胜感激!

这是我运行的代码:

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

【问题讨论】:

    标签: r nvd3.js rcharts


    【解决方案1】:

    你可以这样做:

    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
    

    【讨论】:

    • 非常有用的评论。我相信有一个小错误,文字建议应该是 y = "VALUE" 而不是 y = "PERCENT"
    • 谢谢,确实有一个错误我编辑我的答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多