簡體   English   中英

highcharter 在工具提示中將值轉換為百分比

[英]highcharter convert value to percent in tooltip

我已經制作了一個高章程的樹形圖,我想打印乘以 100 的值並在末尾添加一個百分比符號。 我目前有這段代碼可以生成下面的圖像

hchart(dout, type = "treemap")%>%
  hc_tooltip(pointFormat = "<b>{point.name}</b>:<br>
                             value: {point.value:.3f}%<br>")

樹狀圖工具提示

我在想我需要一個 JS function 將 {point.value:.3f} 乘以 100

我一直在嘗試根據這篇文章來破解一些東西,但我只是不明白 higcharter 或 JS 是如何工作到足以得到它的。 我什至不確定 JS function 是處理它的正確方法嗎?

Yes, I think it would be best to use the Highcharts JS API (formatter function) for this: https://api.highcharts.com/highcharts/tooltip.formatter

Here you can find an article explaining how you can do this in R: https://www.highcharts.com/blog/tutorials/working-with-highcharts-javascript-syntax-in-r/?fbclid=IwAR0fZ97iISS1_itErg69A6ncxI8R1JUuLVAzj4V_af7FE9oPkMBIPR3F9-I

因為我不明白如何使用 JS 集成為我提供的示例,所以我決定以不同的方式解決這個問題,我只是在代碼的前面添加了一行,以將我打印的 df dout 中的值轉換為 point.value在工具提示中,在到達 hchart() function 之前增加 100。 我最初發布的示例代碼無需更改

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM