PieChart

fun PieChart(values: List<Float>, labelPositionProvider: LabelPositionProvider, modifier: Modifier = Modifier, slice: @Composable PieSliceScope.(Int) -> Unit = { val colors = remember(values.size) { generateHueColorPalette(values.size) } DefaultSlice(colors[it]) }, label: @Composable (Int) -> Unit = {}, labelConnector: @Composable LabelConnectorScope.(Int) -> Unit = { StraightLineConnector() }, holeSize: Float = 0.0f, holeContent: @Composable BoxScope.(contentPadding: PaddingValues) -> Unit = {}, minPieDiameter: Dp = 100.dp, maxPieDiameter: Dp = 300.dp, forceCenteredPie: Boolean = false, pieAnimationSpec: AnimationSpec<Float> = KoalaPlotTheme.animationSpec, labelAnimationSpec: AnimationSpec<Float> = tween(LabelFadeInDuration, 0, LinearOutSlowInEasing), pieStartAngle: AngularValue = AngleCCWTop.deg, pieExtendAngle: AngularValue = DegreesFullCircle.deg)

Creates a Pie Chart or, optionally, a Donut Chart if holeSize is nonZero, with optional hole content to place at the center of the donut hole. Pie slices are drawn starting at -90 degrees (top center), progressing clockwise around the pie. Each slice occupies a fraction of the overall pie according to its data value relative to the sum of all values.

Parameters

values

The data values for each pie slice

labelPositionProvider

A provider of label offsets that can be used to implement different label placement strategies. See the PieChart override for a version that uses labels placed around the circumference of the pie.

modifier

Compose Modifiers to be applied to the overall PieChart

slice

Composable for a pie slice.

label

Composable for a pie slice label placed around the perimeter of the pie

labelConnector

Composable for label connectors connecting the pie slice to the label

holeSize

A relative size for an inner hole of the pie, creating a donut chart, with a value between 0 and 1.

holeContent

Optional content that may be placed in the space of the donut hole. To safely draw the content within the hole without intersecting with the chart, apply the passed contentPadding to your content composable.

minPieDiameter

Minimum diameter allowed for the pie.

maxPieDiameter

Maximum diameter allowed for the pie. May be Infinity but not Unspecified.

forceCenteredPie

If true, will force the pie to be centered within its parent, by adjusting (decreasing) the pie size to accommodate label sizes and positions. If false, will maximize the pie diameter.

pieAnimationSpec

Specifies the animation to use when the pie chart is first drawn.

labelAnimationSpec

Specifies the animation to use when the labels are drawn. Drawing of the labels begins after the pie animation is complete.

pieStartAngle

Sets an angle for the pie data to start at. Defaults to the top of the pie.

pieExtendAngle

Sets a max angle for the pie to extend to, with a value between 1 and 360. Defaults to DegreesFullCircle.


fun PieChart(values: List<Float>, labelPositionProvider: LabelPositionProvider, modifier: Modifier = Modifier, slice: @Composable PieSliceScope.(Int) -> Unit = { val colors = remember(values.size) { generateHueColorPalette(values.size) } DefaultSlice(colors[it]) }, label: @Composable (Int) -> Unit = {}, labelConnector: @Composable LabelConnectorScope.(Int) -> Unit = { StraightLineConnector() }, holeSize: Float = 0.0f, holeContent: @Composable BoxScope.(contentPadding: PaddingValues) -> Unit = {}, minPieDiameter: Dp = 100.dp, maxPieDiameter: Dp = 300.dp, forceCenteredPie: Boolean = false, startAnimationUseCase: StartAnimationUseCase = StartAnimationUseCase( executionType = StartAnimationUseCase.ExecutionType.Default, // chart animation KoalaPlotTheme.animationSpec, // label animation tween(LabelFadeInDuration, 0, LinearOutSlowInEasing), ), pieStartAngle: AngularValue = AngleCCWTop.deg, pieExtendAngle: AngularValue = DegreesFullCircle.deg)

Creates a Pie Chart or, optionally, a Donut Chart if holeSize is nonZero, with optional hole content to place at the center of the donut hole. Pie slices are drawn starting at -90 degrees (top center), progressing clockwise around the pie. Each slice occupies a fraction of the overall pie according to its data value relative to the sum of all values.

Parameters

values

The data values for each pie slice

labelPositionProvider

A provider of label offsets that can be used to implement different label placement strategies. See the PieChart override for a version that uses labels placed around the circumference of the pie.

modifier

Compose Modifiers to be applied to the overall PieChart

slice

Composable for a pie slice.

label

Composable for a pie slice label placed around the perimeter of the pie

labelConnector

Composable for label connectors connecting the pie slice to the label

holeSize

A relative size for an inner hole of the pie, creating a donut chart, with a value between 0 and 1.

holeContent

Optional content that may be placed in the space of the donut hole. To safely draw the content within the hole without intersecting with the chart, apply the passed contentPadding to your content composable.

minPieDiameter

Minimum diameter allowed for the pie.

maxPieDiameter

Maximum diameter allowed for the pie. May be Infinity but not Unspecified.

forceCenteredPie

If true, will force the pie to be centered within its parent, by adjusting (decreasing) the pie size to accommodate label sizes and positions. If false, will maximize the pie diameter.

startAnimationUseCase

Controls the animation.

pieStartAngle

Sets an angle for the pie data to start at. Defaults to the top of the pie.

pieExtendAngle

Sets a max angle for the pie to extend to, with a value between 1 and 360. Defaults to DegreesFullCircle.


fun PieChart(values: List<Float>, modifier: Modifier = Modifier, slice: @Composable PieSliceScope.(Int) -> Unit = { val colors = remember(values.size) { generateHueColorPalette(values.size) } DefaultSlice(colors[it]) }, label: @Composable (Int) -> Unit = {}, labelConnector: @Composable LabelConnectorScope.(Int) -> Unit = { StraightLineConnector() }, labelSpacing: Float = DefaultLabelDiameterScale, holeSize: Float = 0.0f, holeContent: @Composable BoxScope.(contentPadding: PaddingValues) -> Unit = {}, minPieDiameter: Dp = 100.dp, maxPieDiameter: Dp = 300.dp, forceCenteredPie: Boolean = false, pieAnimationSpec: AnimationSpec<Float> = KoalaPlotTheme.animationSpec, labelAnimationSpec: AnimationSpec<Float> = tween(LabelFadeInDuration, 0, LinearOutSlowInEasing))

Creates a Pie Chart or, optionally, a Donut Chart if holeSize is nonZero, with optional hole content to place at the center of the donut hole. Pie slices are drawn starting at -90 degrees (top center), progressing clockwise around the pie. Each slice occupies a fraction of the overall pie according to its data value relative to the sum of all values. Places labels around the pie at a minimum distance set by labelSpacing.

Parameters

values

The data values for each pie slice

modifier

Compose Modifiers to be applied to the overall PieChart

slice

Composable for a pie slice.

label

Composable for a pie slice label placed around the perimeter of the pie

labelConnector

Composable for label connectors connecting the pie slice to the label

labelSpacing

A value greater than 1 specifying the distance from the center of the pie at which to place the labels relative to the overall diameter of the pie, where a value of 1 is at the outer edge of the pie. Values between 1.05 and 1.4 tend to work well depending on the size of the labels and overall pie diameter.

holeSize

A relative size for an inner hole of the pie, creating a donut chart, with a value between 0 and 1.

holeContent

Optional content that may be placed in the space of the donut hole.

minPieDiameter

Minimum diameter allowed for the pie.

maxPieDiameter

Maximum diameter allowed for the pie. May be Infinity but not Unspecified.

forceCenteredPie

If true, will force the pie to be centered within its parent, by adjusting (decreasing) the pie size to accommodate label sizes and positions. If false, will maximize the pie diameter.

pieAnimationSpec

Specifies the animation to use when the pie chart is first drawn.

labelAnimationSpec

Specifies the animation to use when the labels are drawn. Drawing of the labels begins after the pie animation is complete.


fun PieChart(values: List<Float>, modifier: Modifier = Modifier, slice: @Composable PieSliceScope.(Int) -> Unit = { val colors = remember(values.size) { generateHueColorPalette(values.size) } DefaultSlice(colors[it]) }, label: @Composable (Int) -> Unit = {}, labelConnector: @Composable LabelConnectorScope.(Int) -> Unit = { StraightLineConnector() }, labelSpacing: Float = DefaultLabelDiameterScale, holeSize: Float = 0.0f, holeContent: @Composable BoxScope.(contentPadding: PaddingValues) -> Unit = {}, minPieDiameter: Dp = 100.dp, maxPieDiameter: Dp = 300.dp, forceCenteredPie: Boolean = false, startAnimationUseCase: StartAnimationUseCase = StartAnimationUseCase( executionType = StartAnimationUseCase.ExecutionType.Default, // chart animation KoalaPlotTheme.animationSpec, // label animation tween(LabelFadeInDuration, 0, LinearOutSlowInEasing), ))

Creates a Pie Chart or, optionally, a Donut Chart if holeSize is nonZero, with optional hole content to place at the center of the donut hole. Pie slices are drawn starting at -90 degrees (top center), progressing clockwise around the pie. Each slice occupies a fraction of the overall pie according to its data value relative to the sum of all values. Places labels around the pie at a minimum distance set by labelSpacing.

Parameters

values

The data values for each pie slice

modifier

Compose Modifiers to be applied to the overall PieChart

slice

Composable for a pie slice.

label

Composable for a pie slice label placed around the perimeter of the pie

labelConnector

Composable for label connectors connecting the pie slice to the label

labelSpacing

A value greater than 1 specifying the distance from the center of the pie at which to place the labels relative to the overall diameter of the pie, where a value of 1 is at the outer edge of the pie. Values between 1.05 and 1.4 tend to work well depending on the size of the labels and overall pie diameter.

holeSize

A relative size for an inner hole of the pie, creating a donut chart, with a value between 0 and 1.

holeContent

Optional content that may be placed in the space of the donut hole.

minPieDiameter

Minimum diameter allowed for the pie.

maxPieDiameter

Maximum diameter allowed for the pie. May be Infinity but not Unspecified.

forceCenteredPie

If true, will force the pie to be centered within its parent, by adjusting (decreasing) the pie size to accommodate label sizes and positions. If false, will maximize the pie diameter.

startAnimationUseCase

Controls the animation.


fun PieChart(modifier: Modifier = Modifier, labelPositionProvider: LabelPositionProvider = CircularLabelPositionProvider(DefaultLabelDiameterScale), holeSize: Float = 0.0f, holeContent: @Composable BoxScope.(contentPadding: PaddingValues) -> Unit = {}, minPieDiameter: Dp = 100.dp, maxPieDiameter: Dp = 300.dp, centeredAlignment: Boolean = true, startAnimationUseCase: StartAnimationUseCase = StartAnimationUseCase( executionType = StartAnimationUseCase.ExecutionType.Default, KoalaPlotTheme.animationSpec, tween(LabelFadeInDuration, 0, LinearOutSlowInEasing), ), pieStartAngle: AngularValue = AngleCCWTop.deg, pieExtendAngle: AngularValue = DegreesFullCircle.deg, content: PieChartScope.() -> Unit)

Creates a Pie Chart or, optionally, a Donut Chart if holeSize is non-zero, with optional holeContent to place at the center of the donut hole.

This version of PieChart uses a DSL-based approach via PieChartScope to define chart items. It features smooth transitions for both slice values and the overall pie diameter when the data or the parent container size changes.

Pie slices are drawn starting at pieStartAngle, progressing clockwise around the pie. Each slice occupies a fraction of the overall pie according to its PieChartScope.item value relative to the sum of all values.

Parameters

modifier

Compose Modifiers to be applied to the overall PieChart.

labelPositionProvider

A provider of label offsets that can be used to implement different label placement strategies. Defaults to CircularLabelPositionProvider.

holeSize

A relative size for an inner hole of the pie, creating a donut chart, with a value between 0 and 1.

holeContent

Optional content that may be placed in the space of the donut hole. To safely draw the content within the hole without intersecting with the chart, apply the passed contentPadding to your content composable.

minPieDiameter

Minimum diameter allowed for the pie.

maxPieDiameter

Maximum diameter allowed for the pie. May be Infinity but not Unspecified.

centeredAlignment

If true, will center the pie within its parent, by adjusting (decreasing) the pie size to accommodate label sizes and positions. If false, will maximize the pie diameter and place it in the top-left most corner of the parent. For the best visual experience when animating the pie due to slice value changes, set centeredAlignment to true.

startAnimationUseCase

Controls the initial grow and fade-in animations of the chart.

pieStartAngle

Sets an angle for the pie data to start at. Defaults to the top center of the pie.

pieExtendAngle

Sets a max angle for the pie to extend to, with a value between 1 and 360 degrees. Defaults to DegreesFullCircle.

content

A DSL block to define the items in the pie chart.