Skip to content

Line Chart

LineChart(
    modifier = Modifier.fillMaxSize().padding(horizontal = 22.dp),
    data = remember {
        listOf(
            Line(
                label = "Windows",
                values = listOf(28.0, 41.0, 5.0, 10.0, 35.0),
                color = SolidColor(Color(0xFF23af92)),
                firstGradientFillColor = Color(0xFF2BC0A1).copy(alpha = .5f),
                secondGradientFillColor = Color.Transparent,
                strokeAnimationSpec = tween(2000, easing = EaseInOutCubic),
                gradientAnimationDelay = 1000,
                drawStyle = DrawStyle.Stroke(width = 2.dp),
            )
        )
    },
    animationMode = AnimationMode.Together(delayBuilder = {
        it * 500L
    }),
)

Zero Line & Negative Values

You can set min & max value for all charts and show zero line:

LineChart(
    data = remember {
        listOf(
            Line(
                label = "Temperature",
                values = listOf(28.0, 41.0, -5.0, 10.0, 35.0),
                color = Brush.radialGradient(...)
            ),
        )
    },
    zeroLineProperties = LineProperties(
        enabled = true,
        color = SolidColor(Color.Red),
    ),
    minValue = -20.0,
    maxValue = 100.0
)

Max value by default is highest value of chart data and Min value is 0 when there is no value under the zero, otherwise it's the lowest data.

Line Color

You can set gradient color for lines:

LineChart(
    data = remember {
        listOf(
            Line(
                label = "Linux",
                values = listOf(28.0, 41.0, 5.0, 10.0, 35.0),
                color = Brush.radialGradient(...)
            ),
        )
    },
)

Line Count

You can add how many lines you want:

LineChart(
    data = remember {
        listOf(
            Line(
                label = "Windows",
                values = listOf(...),
                color = Color.Green,
                curvedEdges = true
            ),
            Line(
                label = "Linux",
                values = listOf(...),
                color = Color.Orange,
                curvedEdges = false
            ),
            Line(
                label = "Linux",
                values = listOf(...),
                color = Color.Blue,
                curvedEdges = true
            ),
        )
    },
    ...
)

Dots & Line Curving

You can show dots and disable line edge curving:

LineChart(
    data = remember {
        listOf(
            Line(
                label = "Windows",
                values = listOf(...),
                color = Color.Orange,
                curvedEdges = true,
                dotProperties = DotProperties(
                    enabled = true,
                    color = SolidColor(Color.White),
                    strokeWidth = 4f,
                    radius = 7f,
                    strokeColor = SolidColor(Color.Orange),
                )
            ),
            Line(
                label = "Linux",
                values = listOf(...),
                color = Color.Cyan,
                curvedEdges = false,
                dotProperties = DotProperties(
                    ...
                )
            ),
        )
    },
    curvedEdges = false
)

Stroke Style

You can make chart line dashed:

LineChart(
    data = remember {
        listOf(
            Line(
                label = "Windows",
                values = listOf(...),
                drawStyle = DrawStyle.Stroke(
                    width = 3.dp,
                    strokeStyle = StrokeStyle.Dashed(intervals = floatArrayOf(10f, 10f), phase = 15f)
                )
                ...
            ),
            Line(
                label = "Linux",
                values = listOf(...),
            ),
        )
    },
)

Fill Color

You can make chart fill color:

LineChart(
    data = listOf(
         Line(
            label = "Windows",
            values = listOf(...),
            color = Color.Orange,
            drawStyle = DrawStyle.Fill,
            ...
         ),
    ),
)