您需要在tooltip選項中使用具有highcharter的JS()函數的格式化程序。此外,Highchart使用'this.point.percentage'來提供百分比。確保不要在第一行末尾忘記%>%
。通過將線(再次magrittr '%>%' 行之前或之後需要)
hchart(test_data, "pie", hcaes(x = Gender, label=Gender,y = Freq, color=colors))%>%
hc_tooltip(formatter = JS("function(){ return '<b>' + this.point.label + ': </b>(Frequency:' +this.y+', Percentage: '+Highcharts.numberFormat(this.percentage)+'%)' }"),useHTML = FALSE)
: hc_plotOptions(pie =list(dataLabels = list(enabled = TRUE,format="{point.label}:{point.y}")))
這應該爲你做的伎倆
您可以在標籤上添加數值或通過與{point.y}
交換:
{point.percentage:.2f}%
,您可以將百分比與標籤一起添加(男,Felame)
來源
2017-06-21 15:43:12
NpT
有沒有方法顯示標籤中的標稱值或百分比,而工具提示中的另一個? – Prometheus
@Prometheus:是:通過 'hc_plotOptions(pie = list(dataLabels = list(enabled = TRUE,format =「{point.label}:{point.y}」)))' 您可以在點之間進行交換。 y用'point.percentage:.2f'來獲取% – NpT