【问题标题】:hPlot pie chart - show percentage in tooltip instead of absolute valueshPlot 饼图 - 在工具提示中显示百分比而不是绝对值
【发布时间】:2015-12-03 11:06:15
【问题描述】:

我正在使用类型 = pie 的 hPlot。我希望工具提示显示总数而不是绝对值的百分比。 我尝试使用以下代码:

piechart<<- hPlot(x = "item", y = "total_purchase", 
               data = as.data.frame(items_purchased), type = "pie") 
 piechart$tooltip(formatter = "#! function() {return(point.percentage:.1f %);} !#")

但现在整个饼图不显示。

【问题讨论】:

    标签: r highcharts shiny rcharts


    【解决方案1】:

    你好,看看这个例子:

    dat <- data.frame(
      VAR1 = letters[1:5],
      FREQ = c(145, 784, 562, 258, 348)
    )
    
    library("rCharts")
    hpie <- Highcharts$new()
    hpie$chart(
      type = "pie"
    )
    hpie$plotOptions(
      pie = list(
        dataLabels = list(enabled = TRUE, format = '<b>{point.name}</b>: {point.percentage:.1f} %')
      )
    )
    hpie$series(
      name = "Example", 
      data = toJSONArray2(obj = dat, json = FALSE, names = FALSE)
    )
    hpie$tooltip(
      formatter = "#!function() {return this.point.name + ' : <b>' + this.y + ' (' + Math.round(this.percentage) + '%)<b>'}!#"
    )
    hpie
    

    在工具提示的格式化程序中,您应该使用this.percentage 而不是point.percentage

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-22
    • 2015-08-16
    相关资源
    最近更新 更多