Charts
Chartsanimated

Multi-line

Two smoothed line series that draw themselves on with rounded joins.

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 MultiLine(
    a: List<Float> = listOf(0.6f, 0.5f, 0.55f, 0.35f, 0.42f, 0.22f, 0.3f),
    b: List<Float> = listOf(0.8f, 0.78f, 0.62f, 0.66f, 0.5f, 0.54f, 0.38f),
    modifier: Modifier = Modifier,
) {
    val draw = remember { Animatable(0f) }
    LaunchedEffect(Unit) {
        draw.animateTo(1f, tween(1100, easing = EaseInOutCubic))
    }
    fun DrawScope.series(pts: List<Float>, color: Color) {
        val step = size.width / (pts.size - 1)
        val path = Path().apply {
            pts.forEachIndexed { i, v ->
                val x = i * step
                val y = size.height * v
                if (i == 0) moveTo(x, y) else lineTo(x, y)
            }
        }
        val measure = PathMeasure().apply { setPath(path, false) }
        val shown = Path().also {
            measure.getSegment(0f, measure.length * draw.value, it, true)
        }
        drawPath(
            shown,
            color,
            style = Stroke(3.dp.toPx(), cap = StrokeCap.Round, join = StrokeJoin.Round),
        )
    }
    Canvas(modifier.fillMaxWidth().height(110.dp)) {
        series(a, Color(0xFF6366F1))
        series(b, Color(0xFF10B981))
    }
}