Charts
Chartsanimated

Horizontal bars

A ranked horizontal bar chart whose bars wipe out from the left in sequence.

Installation

caveui components are copy-paste Jetpack Compose built entirely on Material 3 — there's no caveui dependency to add. Make sure Material 3 is on your classpath (it ships with the Compose BOM), then copy the Usage snippet below into your project.

kotlin
// build.gradle.kts (module)
dependencies {
    implementation(platform("androidx.compose:compose-bom:2025.06.00"))
    implementation("androidx.compose.material3:material3")
}

Usage

kotlin
@Composable
fun HorizontalBars(
    values: List<Float> = listOf(0.9f, 0.74f, 0.6f, 0.42f, 0.28f),
    accent: Color = Color(0xFF6366F1),
    modifier: Modifier = Modifier,
) {
    val grow = remember { Animatable(0f) }
    LaunchedEffect(Unit) {
        grow.animateTo(1f, tween(900, easing = EaseOutCubic))
    }
    val track = MaterialTheme.colorScheme.surfaceVariant
    Canvas(modifier.fillMaxWidth().height(132.dp)) {
        val gap = 12.dp.toPx()
        val bh = (size.height - gap * (values.size - 1)) / values.size
        values.forEachIndexed { i, v ->
            val y = i * (bh + gap)
            val r = CornerRadius(bh / 2)
            drawRoundRect(track, Offset(0f, y), Size(size.width, bh), r)
            drawRoundRect(
                accent,
                Offset(0f, y),
                Size(size.width * v * grow.value, bh),
                r,
            )
        }
    }
}