简体   繁体   English

highcharter 在工具提示中将值转换为百分比

[英]highcharter convert value to percent in tooltip

I've made a treemap in high charter and I want to print the value multiplied by 100 and add a percentage symbol on the end.我已经制作了一个高章程的树形图,我想打印乘以 100 的值并在末尾添加一个百分比符号。 I currently have this code that produces the image below我目前有这段代码可以生成下面的图像

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

树状图工具提示

I'm thinking I need a JS function to multiply {point.value:.3f} by 100我在想我需要一个 JS function 将 {point.value:.3f} 乘以 100

I've been trying to hack together something based on this post but I just don't understand how higcharter or JS work enough to get it.我一直在尝试根据这篇文章来破解一些东西,但我只是不明白 higcharter 或 JS 是如何工作到足以得到它的。 I'm not even sure a JS function is the right way to handle it?我什至不确定 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 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 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

Because I don't understand how to integrate the examples provided for me using JS I decided to attack this problem differently and I just added a line earlier in my code to convert the value in the df dout that I am printing out as point.value in the tooltip, by 100 before it gets to the hchart() function.因为我不明白如何使用 JS 集成为我提供的示例,所以我决定以不同的方式解决这个问题,我只是在代码的前面添加了一行,以将我打印的 df dout 中的值转换为 point.value在工具提示中,在到达 hchart() function 之前增加 100。 No change is necessary to the example code I posted initially我最初发布的示例代码无需更改

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM