SimpleLineChart

fun SimpleLineChart(data: List<LineChartData>, contentDescriptionPrefix: String, emptyLabel: String, modifier: Modifier = Modifier, lineColor: Color = MaterialTheme.colorScheme.primary, fillColor: Color = MaterialTheme.colorScheme.primary.copy(alpha = 0.1f), pointColor: Color = MaterialTheme.colorScheme.primary, gridColor: Color = MaterialTheme.colorScheme.outlineVariant, chartHeight: Dp = DefaultStylishDimensions.lineChartHeight, strokeWidth: Dp = 2.5.dp, pointRadius: Dp = 4.dp, pointInnerRadius: Dp = 2.dp, labelTextSize: Dp = 10.dp, gridLineCount: Int = 5, maxLabelCount: Int = 6, animate: Boolean = true)

A line chart with area fill, grid lines, data-point markers, and categorical X-axis labels, rendered on a Compose Canvas.

Data points from data are plotted left-to-right in list order and connected with straight line segments. The area beneath the line is filled with a semi-transparent fillColor. Each point is marked with a two-tone circle (outer pointColor, inner surface color) for visibility.

The Y axis auto-scales to the data range with 10 % padding above and below. Negative values are clamped to zero for drawing, so the axis floor never drops below zero; non-finite values (NaN, ±Infinity) are excluded from the scale and skipped in drawing. The accessibility description always reflects the original values. Horizontal grid lines carry formatted value labels on the left margin; labels use a locale-neutral one-decimal format.

X-axis labels are automatically thinned to approximately maxLabelCount visible entries (always including the last point) to avoid overlap on dense datasets.

When data contains fewer than two finite points, emptyLabel is drawn at the chart center instead of a line.

On first composition points animate upward from the baseline (see animate); the area fill follows the same animated points. Text layouts (category labels, grid values, and the empty label) are measured once per data change in composition and reused inside the draw scope, so frames do not re-measure text.

This composable is available on all platforms (commonMain). Text is drawn with Compose's common rememberTextMeasurer + drawText APIs.

Parameters

data

Ordered data points to plot.

contentDescriptionPrefix

Leading text for the combined accessibility description (e.g. "Fuel efficiency trend").

emptyLabel

Text displayed at the chart center when data has fewer than two finite entries.

modifier

Modifier applied to the outer Canvas.

lineColor

Stroke color of the connecting line. Defaults to MaterialTheme.colorScheme.primary.

fillColor

Semi-transparent color filling the area between the line and the X axis. Defaults to primary at 10 % alpha.

pointColor

Outer ring color of each data-point marker. Defaults to MaterialTheme.colorScheme.primary.

gridColor

Color of horizontal grid lines. Defaults to MaterialTheme.colorScheme.outlineVariant.

chartHeight

Total height of the chart area. Defaults to DefaultStylishDimensions.lineChartHeight.

strokeWidth

Thickness of the connecting line. Defaults to 2.5 dp.

pointRadius

Outer radius of each data-point circle. Defaults to 4 dp.

pointInnerRadius

Inner (surface-colored) radius of each data-point circle, creating a ring effect. Defaults to 2 dp.

labelTextSize

Text size for axis and category labels. Defaults to 10 dp.

gridLineCount

Number of horizontal grid lines including top and bottom. Defaults to 5.

maxLabelCount

Maximum number of X-axis labels rendered. Labels are evenly sampled; the last data point's label is always included. Defaults to 6.

animate

When true, points animate from the baseline to their target Y positions on first composition using tween(StylishTheme.animation.durationMedium). When false, the chart appears instantly. Defaults to true.

See also