admin管理员组文章数量:1318987
I'm currently using Superset and trying to format the y-axis of a graph to show the number as a percentage.
Values are 0.7, 0.75, 0.9, 1.2, 1.21 and so on.
I'm looking to format these as 0.70%, 0.75%, 0.90%, 1.20%, 1.21% etc. I'm having trouble formatting it in this way. When I use the '.2%' it returns two decimal places, ie. 1.21 turns into 121.00%. Using ',0.01' will return 1.2, 1.21 etc but when adding the percentage to the end, it doesn't show it - also, it doesn't add the second decimal place when it doesn't exist.
Anyone know how to format 2 point decimal places in d3 (specifically for superset, which will only take a string rather than code)
I'm currently using Superset and trying to format the y-axis of a graph to show the number as a percentage.
Values are 0.7, 0.75, 0.9, 1.2, 1.21 and so on.
I'm looking to format these as 0.70%, 0.75%, 0.90%, 1.20%, 1.21% etc. I'm having trouble formatting it in this way. When I use the '.2%' it returns two decimal places, ie. 1.21 turns into 121.00%. Using ',0.01' will return 1.2, 1.21 etc but when adding the percentage to the end, it doesn't show it - also, it doesn't add the second decimal place when it doesn't exist.
Anyone know how to format 2 point decimal places in d3 (specifically for superset, which will only take a string rather than code)
Share Improve this question edited Nov 30, 2022 at 20:30 TylerH 21.1k77 gold badges79 silver badges112 bronze badges asked Oct 2, 2017 at 9:09 ah1ah1 711 gold badge3 silver badges9 bronze badges2 Answers
Reset to default 5In the column tab of edit table in superset you can add a new column of type float , in the sql expression you can give (column_name)/100. so 0.70 will now bee 0.0070 , now you can apply for .2% in the y-axis format .
You can check it here , try just giving the string alone
http://koaning.io/d3-format-tutorial.html
Why don't you simply concatenate them with the string "%"
?
var numbers = [0.7, 0.75, 0.9, 1.2, 1.21];
var format = d3.format(".2f")
numbers.forEach(function(d){
console.log(format(d)+ "%")
})
<script src="https://d3js/d3.v4.min.js"></script>
本文标签: javascriptFormatting a number as a percentage in d3js for SupersetStack Overflow
版权声明:本文标题:javascript - Formatting a number as a percentage in d3.js for Superset - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742055938a2418294.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论