Created
March 13, 2023 01:37
-
-
Save yansusanto/c5ff0932621465d69175b50fba5e308f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const data = [ | |
{ | |
name: 'Cluster 1', | |
value: 210, | |
}, | |
{ | |
name: 'Cluster 2', | |
value: 30, | |
}, | |
{ | |
name: 'Cluster 3', | |
value: 180, | |
}, | |
{ | |
name: 'Cluster 4', | |
value: 260, | |
}, | |
{ | |
name: 'Cluster 5', | |
value: 60, | |
}, | |
].sort((a, b) => a.value - b.value); | |
const total_value = data.reduce((a, b) => a + b.value, 0); | |
// => 740 | |
const convertToPercent = (num) => Math.round((num / total_value) * 100); | |
// convertToPercent(210) => 28 | |
const convertToDegrees = (num) => Math.round((num / 100) * 360); | |
// convertToDegrees(28) => 101 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How To Create Dynamic Donut Charts With TailwindCSS And React