JengaBarChart

fun JengaBarChart(entries: List<JengaBarChartEntry>, barContentDescription: (JengaBarChartEntry) -> String, modifier: Modifier = Modifier, selectedIndex: Int? = null, onSelect: (Int) -> Unit? = null, maxValue: Float? = null, arrangement: JengaBarChartArrangement = JengaBarChartArrangement.Fill, plotHeight: Dp = JengaBarChartDefaults.PlotHeight, minBarHeight: Dp = JengaBarChartDefaults.MinBarHeight, barMaxWidth: Dp = JengaBarChartDefaults.BarMaxWidth, barSpacing: Dp = JengaBarChartDefaults.barSpacing, barShape: Shape = JengaBarChartDefaults.barShape, labelSpacing: Dp = JengaBarChartDefaults.labelSpacing, contentPadding: PaddingValues = JengaBarChartDefaults.contentPadding, labelStyle: TextStyle = JengaBarChartDefaults.labelStyle, selectedLabelStyle: TextStyle = JengaBarChartDefaults.selectedLabelStyle, colors: JengaBarChartColors = JengaBarChartDefaults.colors(), animationSpec: AnimationSpec<Float> = JengaBarChartDefaults.animationSpec, valueLabel: @Composable (entry: JengaBarChartEntry, selected: Boolean) -> Unit? = null, label: @Composable (entry: JengaBarChartEntry, selected: Boolean) -> Unit = { entry, selected -> JengaText( text = entry.label, style = if (selected) selectedLabelStyle else labelStyle, color = if (selected) colors.selectedLabel else colors.label, maxLines = 1, overflow = TextOverflow.Ellipsis, ) })(source)

A vertical bar chart: one bar per entry, growing from a shared baseline, with its label underneath. Bar heights are relative to maxValue and animate when the data changes. With onSelect each bar's whole slot is a tap target and the chart reads as a group of selectable bars; without it the chart is static. There are no axes; put the figure the selection refers to next to the chart, or add a valueLabel at each bar's tip.

Parameters

entries

the bars, in display order; values must not be negative.

barContentDescription

accessibility label for a bar (e.g. "May, 12,000").

modifier

the Modifier for the chart.

selectedIndex

the selected bar, or null for none.

onSelect

called with a tapped bar's index; null makes the chart static.

maxValue

the value of a full-height bar; the largest entry by default.

arrangement

how bars are laid out; see JengaBarChartArrangement.

plotHeight

the height of a full-height bar.

minBarHeight

the height of a zero-value bar.

barMaxWidth

the widest a bar may be.

barSpacing

the gap between bar slots.

barShape

the bar shape.

labelSpacing

the gap between a bar and its label.

contentPadding

padding around the chart.

labelStyle

the label text style.

selectedLabelStyle

the label text style under the selected bar.

colors

the color set; defaults to JengaBarChartDefaults.colors.

animationSpec

how bar heights animate.

valueLabel

optional content above each bar's tip, given the entry and whether it is selected.

label

the content under each bar, given the entry and whether it is selected.

Samples

var selected by remember {
    mutableStateOf<Int?>(
        value = null,
    )
}
val months = listOf(
    JengaBarChartEntry(
        label = "May",
        value = 8200f,
    ),
    JengaBarChartEntry(
        label = "Jun",
        value = 12400f,
    ),
    JengaBarChartEntry(
        label = "Jul",
        value = 9100f,
    ),
)
JengaBarChart(
    entries = months,
    barContentDescription = { "${it.label}, ${it.value}" },
    selectedIndex = selected,
    onSelect = { selected = it },
)