Skip to content

Instantly share code, notes, and snippets.

@ngengesenior
Last active August 24, 2024 16:00
Show Gist options
  • Select an option

  • Save ngengesenior/3d061a0ea31bd5a44e3cbc5d129512da to your computer and use it in GitHub Desktop.

Select an option

Save ngengesenior/3d061a0ea31bd5a44e3cbc5d129512da to your computer and use it in GitHub Desktop.
@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