highcharts 如何在R中使用highchart在饼图中显示总数和百分比?

3mpgtkmj  于 2022-11-10  发布在  Highcharts
关注(0)|答案(1)|浏览(319)

我正在尝试使用Rmarkdown在R中准备一个 Jmeter 板。我使用下面的代码在 Jmeter 板中显示饼图,但是我如何显示总数和百分比

hc <- df %>%
  hchart(
    "pie", hcaes(x = name, y = count))
hc

我的输出只是一个有名称的饼图,但没有数字或百分比。
我想要输出像这样东西

谢谢你的帮助。

wlp8pajw

wlp8pajw1#

使用tooltip.pointFormat(或tooltip.formattooltip.formatter)和dataLabels.format(或dataLabels.formatter)。在这种情况下:

hc_tooltip(pointFormat= "{series.name}: <br>{point.percentage:.1f} %<br>total: {point.total}"),

API参考:https://api.highcharts.com/highcharts/tooltip.pointFormat

hc_plotOptions(series = list(
  dataLabels =  list(format = "<b>{point.name}</b>:<br>{point.percentage:.1f} %<br>total: {point.total}")
        ))

API引用:https://api.highcharts.com/highcharts/plotOptions.series.dataLabels.format
JS演示版:http://jsfiddle.net/BlackLabel/sry5mvzh/

相关问题