Last active
August 24, 2024 16:00
-
-
Save ngengesenior/3d061a0ea31bd5a44e3cbc5d129512da to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| @Composable | |
| @Preview(showBackground = true, showSystemUi = true) | |
| fun PieChartNoAnimation( | |
| items: List<Item> = sampleItems | |
| ) { | |
| Box( | |
| modifier = Modifier.fillMaxSize(), | |
| contentAlignment = Alignment.Center | |
| ) { | |
| val total = items.sumOf { it.value.toDouble() }.toFloat() | |
| val sweepAngles = remember { | |
| items.map { | |
| ((it.value) / total) * 360f | |
| } | |
| } | |
| Canvas( | |
| modifier = Modifier | |
| .size(300.dp) | |
| ) { | |
| var startAngle = -90f | |
| //var currentItem = 0 | |
| for (i in items.indices) { | |
| drawArc( | |
| startAngle = startAngle, | |
| sweepAngle = sweepAngles[i], | |
| color = items[i].color, | |
| useCenter = true | |
| ) | |
| startAngle += sweepAngles[i] | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment