ChartSelection

class ChartSelection(initialIndex: Int? = null, onSelectionChanged: (Int?) -> Unit? = null)(source)

Hoisted selection state for charts that support selecting a single data point (e.g. a pie slice).

Create with rememberChartSelection for interactive charts, or staticChartSelection for an initialized selection used in screenshots and tests. Neither factory disables interaction or animation. The index refers to source data, not an aggregated drawing index; charts are responsible for interpreting it and checking data bounds.

Parameters

onSelectionChanged

Optional callback invoked after a different index is selected or cleared.

initialIndex

The initially selected index, or null for no initial selection.

Constructors

Link copied to clipboard
constructor(initialIndex: Int? = null, onSelectionChanged: (Int?) -> Unit? = null)

Properties

Link copied to clipboard

Optional callback invoked after the selection changes. Initialization, repeated selection of the same index, and clearing an already empty selection do not notify.

Link copied to clipboard

The currently selected index, or null when nothing is selected.

Functions

Link copied to clipboard
fun clear()

Clears the current selection.

Link copied to clipboard
fun renew()

Signals a lifecycle "touch" without changing the selected index. Use to renew timers (e.g. an auto-deselect countdown) when a user re-taps the same point. Does not invoke onSelectionChanged.

Link copied to clipboard
fun select(index: Int)

Selects the data point at index.