Charts
Chartsanimated

Grouped bars

A clustered bar chart comparing two series side by side per category.

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 GroupedBars(
    a: List<Float> = listOf(0.6f, 0.8f, 0.45f, 0.7f),
    b: List<Float> = listOf(0.45f, 0.55f, 0.7f, 0.5f),
    colorA: Color = Color(0xFF6366F1),
    colorB: Color = Color(0xFF34D399),
    modifier: Modifier = Modifier,
) {
    val grow by animateFloatAsState(1f, tween(900, easing = EaseOutCubic), label = "g")
    Canvas(modifier.fillMaxWidth().height(126.dp)) {
        val groupGap = 16.dp.toPx()
        val gw = (size.width - groupGap * (a.size - 1)) / a.size
        val bw = (gw - 4.dp.toPx()) / 2
        fun bar(x: Float, v: Float, c: Color) {
            val h = size.height * v * grow
            drawRoundRect(
                c, Offset(x, size.height - h), Size(bw, h),
                CornerRadius(3.dp.toPx()),
            )
        }
        a.indices.forEach { i ->
            val gx = i * (gw + groupGap)
            bar(gx, a[i], colorA)
            bar(gx + bw + 4.dp.toPx(), b[i], colorB)
        }
    }
}